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.
Test against hostile input
A pattern that finishes quickly on a short example can still hang on a long, almost-matching string.
Sources
- MDN: Regular expressions — MDN Web Docs (accessed 2026-09-01)
Test this in your browser
The tool runs entirely in your browser; the input you use never leaves it.
About the author
Gampangin builds and maintains free, browser-based developer tools and the documentation that makes them trustworthy. The organization is accountable for every page published on this site.