I usually use this AIR app to quickly test regular expressions: http://www.gskinner.com/RegExr/ (there’s a link to the desktop version on the bottom right)
Everything except <, seeing as tha’s where </strong> starts.
That way you don’t have to specify everything you do want to match (like characters with accents, and so on).
I guess you use negative lookahead to look for </strong>, or go for the root all evil: the ANYTHING atom: (.) (just make sure to make it lazy though (.?)).
I’m sorry, but my regex skills are very limited. Still having problems, mainly because I don’t fully understand how preg works.
With the suggestions above, it is returning the boolian response (0 or 1 depending on what I toss in the test string). However, I am wanting the actual “string”.
Using my initial example in this post, how do I get it to extract the string so I can store it in a variable? (either "<strong>over the road</strong> " or even “over the road” would be fine if that is easier.)
If someone could provide me with a full example I would really appreciate it! Thanks.
Run the following code to see how preg_match works:
$matches = array();
$str = "The fox jumped <strong>over the road</strong> and landed on the other side.";
preg_match('/<strong>([^<]+)</strong>/', $str, $matches);
var_dump($matches);
Thanks for the example - it certainly gives me a better idea of how it works.
One problem I found was that this code threw an warning on my system when I tested it.
“Warning: preg_match() [function.preg-match]: Unknown modifier ‘t’ in …”.
The fix was to escape the / in </strong> like this <\/strong>