3 ms·
On the theoretical side, pure regular expressions (w/o PCRE extensions) can actually parse HTML to the extent that most browsers can. The expressions would be g
by mjn 14y ago
On the theoretical side, pure regular expressions (w/o PCRE extensions) can actually parse HTML to the extent that most browsers can. The expressions would be gigantic, unmaintainable messes, and probably not even possible to write by hand, but nonetheless it's more of a practical problem than an issue of formal language power.
For example, WebKit sets a maximum DOM nesting limit of 512 [1], and most other browsers have a limit as well. A context-free language restricted to a finite maximum production depth becomes a regular language, so WebKit's parsing could be done by an NFA or DFA, and the parser could be encoded as a regular expression if desired. But the only plausible way to write such an expression correctly would be to mechanically "compile" it from a grammar. So you're going to need the grammar anyway, at which point you might as well use it directly.
[1] http://trac.webkit.org/browser/trunk/Source/WebCore/page/Settings.h#L408 http://trac.webkit.org/browser/trunk/Source/WebCore/page/Set...