Catastrophic backtracking · static check + safe run
ReDoS Checker
Some regular expressions take seconds, minutes or years on the wrong input. This is called catastrophic backtracking, and attackers use it for ReDoS (regular expression denial of service). Paste a pattern to see whether it has a risky shape before it reaches production.
What the checker looks for
- Nested quantifiers: a repeated group whose content is itself repeated, like
(a+)+or the sample(\w+\s?)+. - Overlapping alternatives inside a repeat, like
(\d|\w)+, where both branches can match the same character. - Runs of adjacent unbounded quantifiers that can split the same text in many ways, like
\w*\w*\w*.
The warning appears under the pattern as you type, saying which kind of risk it found and how to remove it. The check is static: it looks at the pattern's shape, so it works even for languages the browser cannot run.
Two safety nets
A static check can miss unusual cases or flag a pattern that is safe in practice. So RegexLab also runs every pattern in a Web Worker with a 500 ms limit. If a run takes longer, the worker is stopped and replaced, and you see a timeout instead of a frozen tab. To see the problem directly, open the Regex Debugger: a risky pattern on a failing input stops at the 200,000-step limit.
How to fix a risky pattern
- Remove the nesting:
^(\w+\s?)+$becomes^\w+(?:\s\w+)*$, which has exactly one way to match each string. - Make alternatives exclusive:
(\d|\w)+is simply\w+. - Bound the input: limit the length before matching, for example
{1,100}or a length check in code. - Use a linear-time engine where you can. Go's regexp and Rust's regex crate cannot backtrack catastrophically.
Frequently asked questions
- If there is no warning, is my pattern safe?
- It is a good sign, not a guarantee. The checker covers the common shapes behind real ReDoS reports. For patterns that run on untrusted input, also limit input length and test with long strings that almost match.
- Does catastrophic backtracking happen in every language?
- It happens in backtracking engines: JavaScript, Python, PHP (PCRE), Java, C# and Ruby. Go and Rust use automata-based engines with linear-time guarantees, so they are not affected, but they also do not support features such as backreferences.
- Will testing a dangerous pattern freeze my browser?
- No. Matching runs in a separate worker with a 500 ms timeout. If it hangs, the worker is replaced and the page stays responsive.