I had to look at thousands of lines of perl code packed full of regular expressions (some spanning multiple line). It is not a fun thing. Regular expression are extremely powerful, with power comes responsibility :).
I would use them with the consideration that the code I write will have to maintained by someone else few months/years down the line. I would place a few lines of documentation as to what the code is trying to do. It is very hard to document regular expression, placing a example text as to what RegEx is searching for helps.
If I am writing a one time script that won't be used by anyone else, I would unleash the full power for regular expressions.
Do check out this online tool to test your regular expressions. I can't thank enough the author of this tool. http://www.gskinner.com/RegExr/ , it made writing and testing the regular expression much less stressful.
Another great resource to learn regular expressions is at http://www.regular-expressions.info/engine.html
TODO: ADD cheatsheet of regex below!
No comments:
Post a Comment