Habits for Successful Regular Expressions

O’Reilly just announced Damian Conway’s Perl Best Practices book. I tech reviewed the regex chapter - it’s full of great advice.

If you find that’s too much advice, let me recommend my own Five Habits for Successful Regular Expressions.

If that’s still too much advice let me leave you with just two hints: use extended whitespace and test. Nobody can read regular expressions so the least you can do is put in some line breaks and comments. Also you’re going to be tweaking your regex. Everybody does this - regex is the ultimate for code and fix development. What you need is a list of test cases that you can run after each tweak. I recommended a quick and dirty Perl test harness in the article above.

Tags:

Leave a Reply