Regex help with catching the right end point?
Posted: Wed May 18, 2011 2:01 pm
I'm terrible at regex and I must be missing something fundamental here. I'm trying just to get the "I ONLY WANT THIS STRING" in the following example:
But I keep getting multiple parts:
[text]Output:
I ONLY WANT THIS STRING</li><li>NOT THIS ONE</li><li>OR THIS ONE
[/text]
I've tried a variety of patterns, but the closing tag is alluding me as a stopping point for the pattern. Can someone clue me in?
Code: Select all
$html='<li>CAPTURE: I ONLY WANT THIS STRING</li><li>NOT THIS ONE</li><li>OR THIS ONE</li></ul>';
$pattern="/capture:\s(.*)(\<\/LI>)/i";
preg_match($pattern, $html, $results);
echo htmlentities($results[1])
[text]Output:
I ONLY WANT THIS STRING</li><li>NOT THIS ONE</li><li>OR THIS ONE
[/text]
I've tried a variety of patterns, but the closing tag is alluding me as a stopping point for the pattern. Can someone clue me in?