3 ms·
Well, there are problems for which regular expressions are a perfect solution. The problem is when you try to do something like use regular expressions to matc
by Hexstream 17y ago
Well, there are problems for which regular expressions are a perfect solution.
The problem is when you try to do something like use regular expressions to match HTML. If you know the least bit of formal grammar theory, you'll know how maladapted that is.
- baddox 17y agoTo be fair, regexes can still be used when parsing a CFG.
- mlLK 17y agoTo be less fair, it can also be used to parse some strictly written XHTML.
- baddox 17y agoReally? XML tags seem to me to be essentially balanced parentheses.
- mock 17y agoIn perl you can use http://search.cpan.org/~abigail/Regexp-Common-2010010201/lib/Regexp/Common/balanced.pm http://search.cpan.org/~abigail/Regexp-Common-2010010201/lib... The entire Regexp::Common namespace is basically a cookbook of the "right" way to use regular expressions. Worth stealing and porting to other languages...
- MattJ100 17y ago(I shan't confess this is partly an excercise to see how deep HN will nest comments) Lua is interesting in that instead of using traditional regex it comes with its own "pattern" matching - the implementation is much cleaner than most regex implementations. See http://www.lua.org/pil/20.1.html http://www.lua.org/pil/20.1.html for a bit more info. I reply to this comment because Lua patterns actually have an operator to match balanced parentheses (or any pair of characters): %b() Also worth a look if you're feeling bored of regex are PEGs, which leads me nicely onto: http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html (and finally yes, everything I do or speak about does tend to revolve around Lua)