Yow, $30+ for the ebook! I wouldn't buy if just for that chapter… fortunately, the guidelines from the book have been codified as Perl::Critic, so If you don't mind missing out on the gently guiding text which accompanies each rule, you can browse the Perl::Critic::Policy::RegularExpressions[1] submodule docs.
[0]: http://shop.oreilly.com/product/9780596001735.do [1]: https://metacpan.org/pod/Perl::Critic::Policy::RegularExpres...
The programming language constructs are useful in many cases but harder to reason about. The finite automata are easier to reason about but limit themselves to state machines. Here the complexity is that the operator operates in the state-machine space wrapped up inside the programming language construct.
Ok, so I guess I did not give it up as a hobby.
Regexes are declarative and they're really good a narrow set of features - namely, finding text that matches a pattern. When I see someone using negative/positive lookaheads, or trying to match a valid date with a regex, I see someone who is furiously pounding a nail with the fat end of a screwdriver.
If you want to keep things simple with regular expressions:
* Be liberal with what your pattern matches and use a normal programming language for your complicated conditional logic to filter out crap you don't want
* Don't be afraid to break up the search with multiple regular expressions
* Ignore pattern whitespace and use it to visually break up your pattern. Nobody would agree to debug javascript that has been minimized, yet people do this all the time with regex
* For the love of all that is holy, USE NAMED GROUPS. It is a fantastic way to document your intent.
This is confusing: \d{1,2}/\d{1,2}/(\d{4}|\d{2})
This is not:
(?<day>\d{1,2})
/
(?<month>\d{1,2})
/
(?<year>\d{4}|\d{2})