Regex Tester
Test JavaScript regex patterns with highlighted matches, capture groups, named groups and a replacement preview. Runs in a safe worker in your browser.
Enter a pattern to see matches.
Processed locally in your browser. Your data never leaves your device.
About this regex tester
A regular expression describes a pattern of text. This tester runs JavaScript regular expressions against your text as you type, highlights every match, lists the capture groups (numbered and named), and previews the result of a replacement. It runs in a background worker with a time limit, so even a badly written pattern cannot freeze the page.
How to use it
- Type a pattern between the slashes and choose flags.
- Paste the text to test. Matches are highlighted in alternating colours.
- Read the match list for positions and capture groups.
- Optionally type a replacement to preview the result, and copy it.
Quick reference
\ddigit,\wword character,\swhitespace,.any character except a line break.*zero or more,+one or more,?optional,{2,4}between 2 and 4. Add?for the lazy version.^start,$end,\bword boundary.(…)capture group,(?<name>…)named group,(?:…)non-capturing,(?=…)and(?<=…)lookahead and lookbehind.
Avoiding slow patterns
- Avoid nested quantifiers such as
(a+)+or(.*)*: they can take exponential time when the match fails. - Be specific.
[^,]*is safer than.*when you mean "up to the next comma". - Anchor the pattern when you can, and never run untrusted patterns on your own server without a time limit.
Frequently asked questions
- Which regex flavour does this use?
- JavaScript (ECMAScript), the same engine your browser uses. Patterns from PCRE, Python or .NET may differ: for example there are no possessive quantifiers or atomic groups, and lookbehind and named groups use the JavaScript syntax.
- Why did my pattern stop after 2 seconds?
- Some patterns take exponential time on certain inputs, known as catastrophic backtracking. A classic example is (a+)+$ against a long run of a followed by b. Each run happens in a background worker that is terminated after 2 seconds, so the page never freezes. Remove the nested quantifiers or make the pattern more specific.
- What do the flags do?
- g finds all matches, i ignores case, m makes ^ and $ match at every line, s lets . match line breaks, u and v turn on Unicode modes (v is stricter and cannot be combined with u), y matches only at the current position, and d records match positions, which this tool always uses.
- How do I reference groups in the replacement?
- Use $1, $2 for numbered groups, $<name> for named groups, $& for the whole match and $$ for a literal dollar sign.
- Is my text sent to a server?
- No. Patterns run in a worker in your browser, and neither your pattern nor your text is uploaded, stored or logged.