JavaScript Regex Tester
Test a regular expression against sample text, inspect capture groups, or preview a replacement.
Enter the pattern without surrounding slashes.
Use $1 for group 1, $<name> for a named group, or $& for the whole match.
Highlighted matches
Enter a pattern and test text to see matches.
Match details
| Index | Match | Numbered groups | Named groups |
|---|
Replacement result
How to test a regular expression
Enter a pattern such as (?<word>\w+) and paste sample text. Enable g to find all matches or turn it off to see a single match. The table uses zero-based UTF-16 indices, as JavaScript does. A vertical line in the preview marks a zero-length match.
Enable Replace mode to try a replacement. For example, [$&] wraps each match in brackets. Leaving the replacement empty removes the matched text. When the 10,000-match limit is reached, the output replaces only the matches shown.
FAQ
Which regex flavor does this use? It uses your browser’s JavaScript RegExp. Write named groups as (?<name>...) and refer to them in replacements with $<name>. Python’s re uses (?P<name>...) and \g<name>. PCRE supports features such as recursion, which JavaScript does not support.
How does the sticky flag work? With y, the first match must start at index 0. With both g and y, each next match must start where the search left off, so a gap stops matching.
Why might a pattern be slow? Patterns with nested quantifiers can cause catastrophic backtracking on some inputs. Matching runs in a background worker and stops if it takes longer than 1.5 seconds. Try unfamiliar patterns on short samples first.
Is my test text uploaded? Your pattern, test text, and replacement stay in your browser. The tool sends none of them to a server.
Compare the output with Text Diff or clean a list with Remove Duplicate Lines.