News for hackers. Stuff that matters.
Re:Oh Yes You Can Use Regexes to Parse HTML by dancavallaro11 on Friday July 08, 2011 @07:52AM (#2742054)
Yes, HTML is not a regular language, and so cannot be matched with true regular expressions. As mentioned elsewhere, most "regex" libraries in existence today are not limited to simple regular expressions -- they simply wouldn't be powerful enough for many common tasks otherwise.

HTML is more accurately a context-free language (CFL). A regular expression does not allow you to do any sort of counting or stack-based matching in a match, which is required to do things like "I just saw <div>...<a>...<img> so I better see "</img>...</a>...</div>" later on.

The reason the linked solution works is because of the extended capabilities of PCREs, such as backtracking and things like that.

There are no comments on this comment yet.