Matching a string once if another preceding match is false
Posted: Tue Jun 10, 2008 1:40 am
Hello,
I need to match a specific string of chars against a chunk of HTML code. As an example let's say this chunk of HTML code is:
. . .
I need a RegEx expression that matches class="c2" only once (first match) and only if there aren't any closing HTML tags before it. So the match would be successful if ran against the HTML code given above but would be unsuccessful against:
. . .
I would appreciate some help as I seem to not be able to understand the way this whole RegEx thing works and that's deeply frustrating.
I need to match a specific string of chars against a chunk of HTML code. As an example let's say this chunk of HTML code is:
Code: Select all
<tr><td class="nbr"><span [b]class="c2"[/b]>•</span> <a href="http://server.com?id=1234" [b]class="c2"[/b]>Caption goes here</a></td><td class="right">I need a RegEx expression that matches class="c2" only once (first match) and only if there aren't any closing HTML tags before it. So the match would be successful if ran against the HTML code given above but would be unsuccessful against:
Code: Select all
<tr><td class="nbr"><tag>[b]</tag>[/b]<span [b]class="c2"[/b]>•</span> <a href="http://server.com?id=1234" [b]class="c2"[/b]>Caption goes here</a></td><td class="right">I would appreciate some help as I seem to not be able to understand the way this whole RegEx thing works and that's deeply frustrating.