in reply to Parsing nested HTML with just regex
As many computer scientists know, a pure regular expression (one reducible to |, (), * and concatenations) cannot parse balanced characters. See the 'pumping lemma' in any good textbook on language theory; my class used Aho and Ullman's, but I forget the exact title/edition.
As many perl programmers know, perl regexps aren't actually pure because they can call perl code and use backreferences. My perlre page tells me that you can use (?{code}), but I'm not sure, I don't use that construct much.
Finally, I'd be remiss if I failed to tell you not to parse nested structures, especially complex markup, with regexps. Use a parser-- you can find several on CPAN.
|
|---|