When should I not use regular expressions?

Don’t use regular expressions when:

  • the language you are trying to parse is not a regular language, or
  • when there are readily available parsers specifically made for the data you are trying to parse.

Parsing HTML and XML with regular expressions is usually a bad idea both because they are not regular languages and because libraries already exist that can parse it for you.

As another example, if you need to check if an integer is in the range 0-255, it’s easier to understand if you use your language’s library functions to parse it to an integer and then check its numeric value instead of trying to write the regular expression that matches this range.

Leave a Comment