Finding HTML Stuff with Regular Expressions

Following-up my post [cref 69], here’s what I used it for:

<tr\b[^>]*>([\s\S](?!tr\b[^>]*>))*?(String1|String2)[\s\S]*?</tr>

This is an excellent way to find a chunk of HTML with regex. It finds specific table rows containing either “String1” or “String2”, regardless of linefeeds, carriage returns, or other nefarious forms of whitespace.

Adapted from one of the more simple incarnations in Steve Levithan’s post about evolving a regex to find innermost HTML elements. Could be more complete and/or efficient.. but at least this one is fairly easy (kinda) to understand.

Testing Regular Expressions with Expresso

This cool little tool from Ultrapico saved me a ton of time while attempting to whack together a fairly complex regex today. Though it can be a bit clunky at times, in general Expresso is extremely useful for visualizing how your regular expressions are stepping through test data. The layout is simple and intuitive. And best of all, it’s free.

Expresso

Also played around with JanĀ Goyvaerts’ RegexBuddy, which is definitely the more slick of the two (real-time search while typing) and highly recommended by flagrant regex badass at large Steve Levithan. Nevertheless I found it easier to see what was going on in Expresso and, as I may have mentioned above… free.