DEV Community

Discussion on: What are your code smells and/or best practices with regular expressions?

Collapse
 
jtvanwage profile image
John Van Wagenen

This. Amen. I was about to say something similar.

Quick story: when I started with my current employer, one of the first things I did with my mentor was strip out over 900 regular expressions and replace them with an HTML parser. One lesson that was hit home during that time is regular expressions are for "Regular" languages (meaning they have some predictable pattern to them). In our case, HTML is not a regular language and regular expressions was a poor choice that caused many, many bugs. It got much better when we replaced them with an HTML parser.