JavaScript Regex Tester — Live Matches, Groups & Explainer
Test regular expressions live — match highlighting, capture groups, a $1-replacement preview, plain-English explainer and backtracking-hazard check.
$1–$99 group text · $& whole match · $` before / $' after · $<name> named group · $$ a literal dollar sign
Pattern library — with honest caveats
Every pattern in this library comes with the limits a real user should know — click one and read the note it loads.
What each mode does
Matches lists every match with its index range and re-renders your test string underneath with each capture group in its own color — group 1 cyan, group 2 orange, and so on through nested groups. Indices come from the engine itself (the d flag is added internally), so a match reported at index 3–5 is exactly where exec() found it. Replace runs real String.replace() on your input, so $1, $& and $<name> behave exactly as they will in your code. Explain tokenizes the pattern left to right — every class, quantifier, group, anchor and lookaround gets a one-line plain-English description, including how the m and s flags would change ^, $ and .. It’s the fastest way to read a regex someone else wrote.
The flags, honestly
The checkboxes are the six JavaScript flags that change matching: g finds every match instead of the first, i folds case, m makes ^/$ match at line boundaries, s lets . match newlines, u enables full Unicode semantics (\p{…}, code-point escapes, surrogate handling) and y makes the match sticky to lastIndex. This tester doesn’t paper over JS semantics — without g you’ll see one match, because that’s what your code will get. (The seventh flag, d, adds group indices and is applied internally for the highlighting; it never changes what matches.)
Why offline matters
Regex testing means pasting real data — log lines, user input, sometimes secrets. Every well-known tester phones your pattern home for sharing features you didn’t ask for. This one is a static page: once loaded it works with the network cable unplugged, which you can verify in your browser’s dev tools. Nothing you type leaves the tab.
New to the syntax? The regex cheat sheet covers the JavaScript dialect in tables you can scan. Before you copy an “email validator” into production, read why email regex is a trap. And if the tool just flagged your pattern with a backtracking warning, catastrophic backtracking explained walks through why (a+)+ melts down and how to fix it.
Frequently asked questions
Does my regex or test string get uploaded?
No. This page is a static file — matching, replacing and the explainer all run in JavaScript inside your browser tab, against your browser's own regex engine. Load the page, go offline, and it still works. The privacy policy covers the small print.
Which regex flavor does this tester use?
JavaScript — the same RegExp your Node.js or browser code uses. That's deliberate: patterns here behave exactly like they'll behave in your JS, including quirks like \w being ASCII-only, . skipping newlines unless s is set, and the u flag changing what's even legal to write. PCRE/Python/Java patterns are mostly similar but differ at the edges (possessive quantifiers, atomic groups, \R, lookbehind rules).
Why do I only see one match?
Because that's what JavaScript does without the g flag — a regex without g returns the first match only, and this tester mirrors that faithfully. Tick g and you'll get every match with its index range, exactly as matchAll would return them.
What do $1, $& and $<name> mean in the replacement?
They are JavaScript's substitution tokens: $1–$99 insert the text a capture group saved, $& is the whole match, $` and $' are the text before and after it, $<name> inserts a named group's text, and $$ is a literal dollar sign. The replace preview runs real String.replace(), so what you see is exactly what your code will produce.
How reliable is the backtracking warning?
It's a heuristic, not a proof. It catches the classic bomb shapes — a repeated group containing an unbounded repetition like (a+)+ or (\w+)*, and alternation where several branches can eat the same characters like (a|aa)+. It won't catch every slow pattern, and a warning doesn't guarantee exponential behavior — it means "test this with a long failing input". The backtracking article shows how to do that.
Can I use this for regexes in Python, PCRE or Java?
For simple patterns — literals, classes, basic quantifiers and groups — yes, the behavior matches closely enough to prototype. But don't trust it for lookbehind edge cases, possessive/atomic constructs (a++, (?>…)) which JavaScript lacks, \R/\A/\z anchors, or Unicode-property subtleties. If it matters, re-verify in your target engine.
Why does the email pattern in the library reject some valid addresses?
On purpose — the note under it says exactly where it lies. Full RFC 5322 email validation in regex is famously a losing game (quoted local parts, comments, nested escaping); the practical pattern is a shape check plus sending a confirmation email. Why email regex is a trap goes into the details.
Latest articles
Catastrophic Backtracking, Explained
(a+)+b takes ~2^n steps on a string of n a's. Walk through exactly why, learn to spot the shape, and see the rewrites that make it linear.
Why Email Regex Is a Trap
Every email regex you've copy-pasted rejects real addresses and accepts fake ones. Here's why that's structural, not fixable — and the two-line strategy that actually works.
JavaScript Regex Cheat Sheet
Anchors, classes, quantifiers, groups, lookarounds, flags and replace tokens — the JavaScript dialect of regex in tables you can scan mid-debugging.