Cheatsheet Pages / Regex Cheatsheet
Catastrophic backtracking: the regex that hangs — and the fix
A pattern like (a+)+$ can take longer than the age of the universe on non-matching input.
Patterns use the syntax shared by PCRE / Python / JavaScript; engine differences are flagged in the cheatsheet where they matter. Test any pattern at regex101.com — and pick the matching engine.
(a+)+$
# DANGER: on "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa!" this hangs
(a+)$
# safe: one quantifier, linear time
Good to know
Nested quantifiers make the engine try exponentially many paths. Fix it with atomic groups (PCRE/Java) or rewrite the pattern to be specific — one quantifier, linear time.
