3 ms·
> Now I understood the reason _why_ you can't use regular expressions to parse HTML is that HTML is usually not regular. Is this true? From the comments: Q. "
by Terretta 15y ago
> Now I understood the reason _why_ you can't use regular expressions to parse HTML is that HTML is usually not regular. Is this true?
From the comments:
Q. "The answer is you can't. HTML is not regular so be definition it can't be described by a regular expression."
A. "Your use of REGULAR in regular expressions has been irrelevant and wrong since Ken Thompson first put backrefs into regexes around 40 years ago. /(.)\1/ parses non-REGULAR languages perfectly well. Please stop repeating this nonsense. – tchrist"
- adobriyan 15y agoBackreferences in some sense don't work because real HTML contains misnesteded tags and other bugs, so many of them, even HTML5 spec explictely mentions correction algo.
- FaceKicker 15y agoWhy is the language matched by /(.)\1/ non-regular? Isn't it finite (aa, bb, cc, dd, ..., zz if your alphabet is the lowercase letters a-z)? And all finite languages are trivially regular. Maybe he meant /(.*)\1/? Note: I know that backreferences make Perl regexes capable of matching non-regular languages, but this doesn't seem like an example of that.