Jump to content

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';

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.