How do I make a regex that stops at a phrase? I keep finding it but I can't get it.
Say, I wanted to grab the stuff between two <b>,</b>, and the text is <b>x<>x</b>
How would I tell it to stop at </b>?
You could use look-behind and look-ahead assertions (the "(?<=...) and (?=...), below) along with the ngreedy modifier:
preg_match_all('#(?<=<b>).*(?=</b>)#isU', $text, $matches); // to view the matches: foreach($matches[0] as $match) { echo "<p>$match</p>\n"; }
thanks, what does the # do?
In this context, it is just the regular expression delimiter. The / is also commonly used for this purpose.
When I'm dealing with HTML/XML-related regular expressions, I like to use something other than the "/" as the regexp delimiter so that I don't have to escape the literal slashes that tend to appear, such as in closing tags and URLs.