Regex Tester — Test & Debug Regular Expressions
Test a JavaScript regular expression against any text. Live match highlights, capture groups, replacement preview, flag toggles, and a construct-by-construct explainer — every keystroke processed locally in your browser.
How it works
The tester wraps three JavaScript primitives: new RegExp(pattern, flags) for compilation, String.prototype.matchAll for iteration, and String.prototype.replace for the rewrite. The whole thing is a pure function — no server call, no shared state, no dependency beyond the standard library.
- Compile.Your pattern and the flag toggles are passed to the JavaScript engine's own RegExp constructor. The
gflag is added unconditionally so iteration over multiple matches is well defined; any syntax error surfaces under the field with the engine's native diagnostic message rather than a generic "invalid pattern" string. - Match. The tool calls
text.matchAll(regex)to walk every non-overlapping match. Zero-width matches (anchors like^, lookarounds) are advanced past by the engine's AdvanceStringIndex algorithm in ECMA-262 §22.2.7.4, so a pattern like(?=\d)terminates instead of spinning forever. - Extract groups. For each match the tool reads
m[1]throughm[n]for numbered captures andm.groupsfor named captures. The numbered groups list also surfaces the name (if any) by parsing the source pattern's group order — that gives a clean$1 (year)label even when several named groups share a value. - Replace. A fresh compiled regex is passed to
text.replacewith the replacement string verbatim, so$1,$&,$`,$', and$<name>expand per ECMA-262 §22.1.3.18. The result is what your code would produce with the same pattern, byte for byte. - Cross-check. A second counter runs through
replacewith a counting callback. The Verified badge stays green only when both counters agree on the number of matches — the invariantcountByMatchAll === countByReplacemust hold for every well-formed input. - Explain.The Explain tab tokenises your pattern and names each construct — anchors, character classes, capture groups, quantifiers, escapes. It is a structural walk, not a full parser; tokens it cannot classify fall through as "literal", and the engine itself remains the authoritative source of truth for what compiles.
The flag set is the standard ECMA-262 alphabet: g global, i case-insensitive, m multiline, s dot-all, u Unicode, and y sticky. The Unicode flag enables \p{...} property escapes from Unicode TR-18, so a pattern like \p{L}+ matches a run of letters in any script — Sinhala (සිංහල), Tamil (தமிழ்), Cyrillic, accented Latin, CJK.
Performance: a megabyte of text against a typical pattern resolves in single-digit milliseconds on a mid-range phone. The page caps the input at 1,000,000 characters and the pattern at 10,000 — past those, the input is trimmed and a notice appears. Catastrophic backtracking is the one workload the tool cannot magically fix — if a pattern feels stuck, anchor it or rewrite the alternation; the iteration cap stops it from freezing the page.
Worked examples
Frequently asked questions
Sources & references
- ECMA-262 — RegExp objects, flags, and AdvanceStringIndex
- ECMA-262 — String.prototype.matchAll iterator semantics
- ECMA-262 — String.prototype.replace and replacement-string tokens
- Unicode Technical Report #18 — Unicode Regular Expressions
- MDN — RegExp reference (flags, Unicode property escapes)
- MDN — Regular expressions cheatsheet
The tool's match and replace semantics were last cross-checked against the JavaScript engine on 2026-05-11. The page is reviewed whenever a relevant TC39 proposal lands — for example the v flag for set operations — or a Unicode TR update changes the property-escape definitions.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a regex edge case, a count mismatch, or want a new preset?
Email me at [email protected] — most fixes ship within 24 hours.