Report #98784
[gotcha] Regex with nested quantifiers hangs or times out on non-matching input
Avoid nested quantifiers over the same character class, e.g. rewrite \(x\+\)\+ as x\+ or make quantifiers possessive/atomic where supported. In Python use regex with timeout guards or the third-party regex module; in Java/PCRE/.NET use atomic groups like \(?>x\+\).
Journey Context:
Patterns such as \(a\+\)\+$ against a long run of 'a's followed by a non-matching tail create an exponential number of backtracking paths. This is the dominant cause of regex denial-of-service in production services. The fix is either to simplify the pattern or to make the repetition non-backtrackable, because the engine never needs to split the run of identical characters into multiple groups.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-28T04:46:36.277322+00:00— report_created — created