News for hackers. Stuff that matters.
Re:Regular Expression Matching can be Ugly and Slow by mlLK on Sunday March 14, 2010 @11:10AM (#1190742)
Although this might not be applicable given the topic, someone might as well say it:

> Some people, when confronted with a problem, think "I know, I’ll use regular expressions." Now they have two problems. --Jamie Zawinski

As a sort of 'untold' rule of thumb, I avoid writing regex scripts like the plague and let my macros do all the globbing. Although I'm sure writing stuff in bash or C on a regular basis would trump this rule altogether, but, then again, I also avoid writing/reading anything in bash or C like the plague as well. sighs

Re:Regular Expression Matching can be Ugly and Slow by fragmede on Sunday March 14, 2010 @11:36AM (#1190770)
The original quote is: “If you have a problem and you think awk(1) is the solution, then you have two problems.” -David Tilbrook (http://regex.info/blog/2006-09-15/247)
Re:Regular Expression Matching can be Ugly and Slow by icefox on Sunday March 14, 2010 @05:21PM (#1191337)
What if my only other choice was sed or perl?
Re:Regular Expression Matching can be Ugly and Slow by Hexstream on Sunday March 14, 2010 @11:59AM (#1190798)
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.

Re:Regular Expression Matching can be Ugly and Slow by baddox on Sunday March 14, 2010 @03:20PM (#1191138)
To be fair, regexes can still be used when parsing a CFG.
Re:Regular Expression Matching can be Ugly and Slow by mlLK on Sunday March 14, 2010 @03:23PM (#1191149)
To be less fair, it can also be used to parse some strictly written XHTML.
Re:Regular Expression Matching can be Ugly and Slow by baddox on Sunday March 14, 2010 @05:23PM (#1191342)
Really? XML tags seem to me to be essentially balanced parentheses.
Re:Regular Expression Matching can be Ugly and Slow by MattJ100 on Sunday March 14, 2010 @09:18PM (#1191729)
(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 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

(and finally yes, everything I do or speak about does tend to revolve around Lua)

Re:Regular Expression Matching can be Ugly and Slow by mock on Sunday March 14, 2010 @09:24PM (#1191747)
In perl you can use 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...