Friday, June 27, 2008

On Regular Expressions

Jeff Atwood loves him some regular expressions.
You may find it a little odd that a hack who grew up using a language with the ain't keyword would fall so head over heels in love with something as obtuse and arcane as regular expressions. I'm not sure how that works. But it does. Regular expressions rock.They should absolutely be a key part of every modern coder's toolkit.

Okay, fine. I've used regular expressions, but not a whole bunch. I'm not even a coder but I can use them for my job. I should really get down and dirty with them.

The above link led me to this

Used responsibly, regular expressions are a huge net positive. What seperates regex use from regex abuse? Take a gander at this 6.2kb monster for validating RFC822 email addresses:

(code block omitted to prevent explodey heads)

The author comments that [this] somewhat pushes the limits of what it is sensible to do with regular expressions, to which I respond: somewhat? This is a 6,343 character pattern. How many more characters does it take to reach the limit of sensibility? It's abusive. I pity the poor developer who has to troubleshoot this behemoth.


Me, I wonder at the mind that could produce something like that without clapping a grenade to the side of his head.
blog comments powered by Disqus