JavaScript Regex Tester & Match Highlighter
Test a JavaScript regular expression against your text, highlight every match, inspect capture groups and preview replacements. Runs in your browser's native RegExp engine.
Your text never leaves your browser.
Type the pattern without surrounding slashes. JavaScript (ECMAScript) syntax.0 / 2,000 UTF-16 units
Match preview
Whitespace and line breaks preservedPreview String.prototype.replace. With g, every match is replaced.
Summary
Enter a pattern to start matching.
- Matches
- —
- Capture groups
- —
- Test text (UTF-16 code units)
- 0
- Test text (Unicode code points)
- 0
Matches
No matches to show.
How to test a regular expression
Type the pattern without the surrounding slashes, choose flags and paste the text to test. Matches are highlighted about 200 milliseconds after you stop typing, and each one is listed with its offsets and capture groups. Empty matches, such as those produced by ^ or \b, appear as a thin marker in the preview so you can see where they occur.
What the regex flags mean
| Flag | Name | Effect |
|---|---|---|
| g | Global | Returns every match. Without it, matching and replacing stop after the first match. |
| i | Ignore case | foo also matches Foo and FOO. |
| m | Multiline | ^ and $ match at line breaks, not only at the start and end of the whole text. |
| s | Dot all | The dot . also matches \n and other line terminators. |
| u | Unicode | Matches by code point, enables \p{…} property escapes and applies stricter syntax. |
Numbered and named capture groups
Parentheses create numbered groups from left to right; (?:…) groups without capturing, and (?<name>…) adds a name. For each match the tester shows every group with its value and offsets. An optional group that did not participate is marked as not matched, which is different from a group that captured an empty string.
Replacement syntax
Replace mode previews exactly what String.prototype.replace would return. With g every match is replaced; without it only the first one. A $ that is not part of a valid token is kept as typed, and a reference to a group number that does not exist stays literal.
| Token | Inserts |
|---|---|
| $& | The whole match |
| $1 … $99 | A numbered capture group |
| $<name> | A named group (?<name>…) |
| $` | Text before the match |
| $' | Text after the match |
| $$ | A literal $ |
Unicode and offsets
Offsets are zero-based UTF-16 code units, matching JavaScript string indexes and slice(). An emoji outside the Basic Multilingual Plane occupies two code units, so the summary counts code units and Unicode code points separately. With the u flag a dot or an empty match advances by a whole code point, never splitting a surrogate pair.
Timeouts and limits
Backtracking regular expressions can take exponential time. Every test runs in a separate background worker that is terminated after about 1.5 seconds, so the page stays responsive and no partial result is shown. The pattern is limited to 2,000 and the test text to 100,000 UTF-16 code units; at most 500 matches are listed, and a replacement result over 200,000 code units is not produced.
JavaScript regex vs PCRE and Python
This tool runs your browser's ECMAScript engine, so results match Node.js and front-end code. Other flavors differ: PCRE and PHP support possessive quantifiers, atomic groups and recursion; Python uses \Z and (?P<name>…); .NET allows variable-length lookbehind with different rules. Test those patterns in their own environments before relying on them.
Related tools
To apply a pattern to a document and copy the result, use Find & Replace Text. To review what a replacement changed line by line, paste the before and after into the Text Difference Checker. Hidden characters that make a pattern fail unexpectedly can be found with the Invisible Character Detector.
Frequently asked questions
Which regex flavor does this tester use?
It uses the JavaScript (ECMAScript) RegExp engine built into your browser, the same one used by String.prototype.match and replace. Features specific to PCRE, Python or .NET, such as possessive quantifiers, atomic groups, recursion or inline modifiers like (?i), are not supported and show a syntax error.
Why do I only see one match?
Without the g (global) flag, JavaScript stops at the first match, and Replace mode only replaces that first occurrence. Turn on g to list and replace every match.
What is the difference between a missing capture group and an empty one?
An optional group that did not take part in the match is undefined and is shown as not matched. A group that matched zero characters is an empty string. In a replacement, both insert nothing.
How do I use capture groups in the replacement?
Use $1, $2 and so on for numbered groups, $<name> for a named group (?<name>...), $& for the whole match, $` for the text before the match, $' for the text after it, and $$ for a literal dollar sign.
Why are the offsets different from the number of characters I see?
Start and end offsets are zero-based UTF-16 code units, the same as JavaScript string indexes. Emoji and many rarer symbols take two code units, so 😀 in a😀b spans offsets 1 to 3. The summary shows code units and Unicode code points separately.
What does the u flag change?
Unicode mode treats surrogate pairs as single code points, enables property escapes such as \p{L} for any letter, and makes the syntax stricter, so some escapes that are tolerated without u become errors.
Why was my pattern stopped?
Some patterns, such as nested quantifiers like (a+)+$, can take exponential time on text that almost matches. Each test runs in a background worker that is stopped after about 1.5 seconds, so the page stays responsive. Simplify the pattern or shorten the text and try again.
Is my text sent anywhere?
No. The pattern, test text and replacement are processed locally in your browser and are not uploaded, stored or added to the URL.