Trying to use Regular Expressions to extract a pieces of a string given string startX and endY, then grab everything between.
i.e.
~ startX grab this unknown content endY ~~~

Sample Code
<?
$string ="Hello World and Goodbye World"; //Attempting to retrieve-> World and Goodbye

//___________\/ This should tell the RegEx to start looking here, but it isn't working.....
preg_match("/(?<=Hello ).*(?= World)/" , $string , $World_and_Goodbye);
echo "Matched: " . $World_and_Goodbye[0] . "<br>\n";

//__________\/ This kind of works, but you have to include that that char in the output, then strip it...
preg_match("/o .* (?=World)/i" , $string , $World_and_Goodbye);
echo "Matched: " . $World_and_Goodbye[0] . "<br>\n";
?>

The lookbehind seems to nullify any match attempt, while the lookahead is working flawlessly.

backup IMG URL
RegEX Coach says I'm not insane

Am I mis-interpreting the function of the lookbehind, or is there a better way to extract unknown info between two known strings?

I thank you for your time, and greatly appreciate any response/input you might have.

    try this

    <?
    $string ="Hello World and Goodbye World";
    $start="Hello";
    $end="World";
    
    preg_match("/$start(.+)$end/i",$string,$World_and_Goodbye);
    print_r($World_and_Goodbye);
    ?>
    
      Write a Reply...