Cheat sheet
How it works
Regex Tester highlights matches in your text as you type a regular expression and shows capture groups. A built-in cheat sheet makes it handy for learning too. It's useful for validating patterns, cleaning data and searching through code.
Quick start
- Enter a regular expression and choose your flags.
- Paste test text and watch the matches highlight.
- Check the capture groups and refine the expression.
Frequently asked questions
What are capture groups?
Parts of the pattern in parentheses that pull out a piece of the match, such as the day, month and year from a date.
What do flags do?
For example, g finds all matches, and i ignores the difference between upper and lower case.
Will it behave like my programming language?
It uses the JavaScript regex engine, so small differences from other languages can appear.
Greedy vs lazy, anchors and the backtracking cliff
Three ideas that explain most regex surprises. · 5 min read
Quantifiers are greedy by default
A quantifier matches as much as it can and backtracks only when forced: given '<b>one</b><b>two</b>' and the pattern <.*>, the match runs from the first < to the very last > — one huge match, not two. Add a question mark (<.*?>) and the quantifier becomes lazy: it stops at the first opportunity, giving the two separate tags you probably wanted. Alternatives exist for both strategies: negated character classes ([^<]*), which never overreach because they can't match the delimiter at all.
Anchors and word boundaries
^ and $ anchor to the start and end of the line (or string, depending on flags), turning a loose pattern into an exact shape — ^\d{4}$ matches exactly four digits, not 'four digits somewhere'. \b matches the boundary between a word character and a non-word character, so \bcat\b finds cat but not category. Between anchors, boundaries and explicit character classes, most 'regex is unpredictable' experiences come from patterns that were looser than they looked.
The backtracking cliff
Nested quantifiers — think (a+)+ or (\w+\s?)* — can make the engine try exponentially many paths on adversarial input, hanging a CPU for seconds or minutes on one request (ReDoS). The defenses: avoid nested quantifiers over overlapping classes, anchor patterns when possible, and treat any pattern with a + inside a quantified group as suspect until tested. This tool runs the JavaScript engine, so its behavior — including the cliff — matches what your Node or browser code will do.