Common Regex Mistakes

The regular-expression mistakes that cause failed matches and catastrophic backtracking.

Most broken regular expressions fail for one of a handful of reasons: an unescaped metacharacter, a greedy quantifier that consumes too much, or a pattern that backtracks exponentially on long input.

01Frequent mistakes

  • Forgetting to escape . or + when a literal character is meant.
  • Assuming ^ and $ match line boundaries without the m flag.
  • Using .* where a non-greedy .*? or a character class is safer.
  • Nesting quantifiers in a way that causes catastrophic backtracking.

Sources

  1. MDN: Regular expressions — MDN Web Docs (accessed 2026-09-01)