3 ms·
> while for "parse an apache log line" you'd probably use a grammar instead of a very nasty regex. That's actually a fairly easy endeavor with perl regex capab
by kbenson 9y ago
> while for "parse an apache log line" you'd probably use a grammar instead of a very nasty regex.
That's actually a fairly easy endeavor with perl regex capabilities, especially named captures. Parsing HTML, or a programming language, or other much more complex structures is much easier with a grammar. For example, JSON parsing[1].
That said, there are ways to approximate some features of grammars with Perl5 regexes[2].
1: https://github.com/moritz/json/blob/master/lib/JSON/Tiny/Grammar.pm https://github.com/moritz/json/blob/master/lib/JSON/Tiny/Gra...
2: http://blogs.perl.org/users/brian_d_foy/2013/10/parsing-json-with-a-single-regex.html http://blogs.perl.org/users/brian_d_foy/2013/10/parsing-json...