Jump to content

[SOLVED] regular expression


ess14

Recommended Posts

having a little trouble with this expression....im very new to regular expressions, so its no wonder im having trouble.

As you can see (when u run this script) im getting no output.

the problem seems to be the fullstop (.)

how do i get the array to return the word 'lambs.'?

even when i try escape the full stop, its like the stop is still stuffing things up...what am i missing?

 

function findinside($start, $end, $string) {
        preg_match_all('/' . preg_quote($start, '/') . '([^\.)]+)'. preg_quote($end, '/').'/i', $string, $m);
        return $m[1];
    }
    
    $start = "13";
    $end = "mary";
    $string = "mary has 6 lambs. phil has 13 lambs. mary stole phil's lambs. now mary has all the lambs.";

    $out = findinside($start, $end, $string);

    print_r ($out);

Link to comment
https://forums.phpfreaks.com/topic/100284-solved-regular-expression/
Share on other sites

Wrong forum... but do you want as many results as possible, or as few? IE

 

$start = 'mary';

$end = 'lambs';

 

$string = 'there are 5 lambs. mary has 3 lambs and john has 2 lambs';

or

$string = 'there are 5 lambs. mary has 3 lambs and john has 2 lambs';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.