Regex Tester
Test a regular expression live, with every match and capture group shown.
About the regex tester
Type a pattern and it is matched against your test string as you type, with every match highlighted in place. Underneath, each match is listed with its position and every capture group β numbered and named β so you can see exactly what the pattern is picking up rather than guessing from a highlight.
All six JavaScript flags are toggleable, there are ready-made patterns for the common
cases, and a replacement field shows the result of String.replace with
$1, $2 and $<name> substitutions.
This uses the JavaScript regular expression engine, so the behaviour matches what you will get in Node and in the browser. PCRE, Python and Go differ in places β most visibly around lookbehind and named group syntax.
A short reference for the pieces
\ddigit Β·\wword character Β·\swhitespace Β·.any character*zero or more Β·+one or more Β·?optional Β·{2,5}a counted range^start Β·$end Β·\bword boundary[abc]any of these Β·[^abc]none of these Β·(a|b)either(...)capture group Β·(?:...)group without capturing Β·(?<name>...)named group(?=...)lookahead Β·(?<=...)lookbehind
Add ? after a quantifier to make it lazy: .*? matches as
little as possible, which is usually what you want between two delimiters.
Catastrophic backtracking, and why patterns hang
Some patterns take exponential time on input that nearly matches. Nested quantifiers
are the classic trigger β (a+)+b against a long run of a's will effectively
never finish, because the engine tries every way of splitting the string before giving up.
The fix is almost always to make the inner pattern more specific so there is only one way to match, rather than adding more quantifiers. Test strings here are capped at 100,000 characters to limit the damage a pattern like that can do to your browser tab.
Frequently asked questions
What does the g flag do?
Global β it finds every match rather than stopping at the first. Without it, only the first match is returned and a replace call substitutes only that one.
How do I match text between two characters?
Use a lazy quantifier so it stops at the first closing delimiter rather than the last: \[(.*?)\] captures what is inside square brackets. The greedy version .* would run to the final bracket in the string.
What is the difference between (...) and (?:...)?
Both group, but only the first captures. Use a non-capturing group (?:...) when you just need to apply a quantifier to several characters and do not want the result cluttering your group numbering.
Does this match how regex works in Python or PHP?
Mostly, but not exactly. This uses the JavaScript engine. Python and PCRE differ around named group syntax, lookbehind support and some escape sequences, so test in your target language before relying on an edge case.
Why does my regex make the page freeze?
Almost certainly catastrophic backtracking from nested quantifiers such as (a+)+ or (.*)*. Rewrite so there is only one way for the pattern to match a given string.