Regex tester

Test JavaScript regular expressions: highlight matches, list named groups, replace with $1 and get syntax errors explained in plain words.

You can also paste a literal such as /\d+/gi.

Flags
Waiting for input

Type a pattern and some text: matches are highlighted here.

Cheat sheet
.
Any character except a line break
\d \w \s
Digit, word character, whitespace
\D \W \S
The opposite of the above
[abc] [^abc] [a-z]
One of, none of, range
^ $
Start and end (of line with the m flag)
\b
Word boundary
* + ?
0 or more, 1 or more, 0 or 1
{3} {2,5} {2,}
Exactly, between, at least
*? +?
Lazy version (as few as possible)
(…) (?:…)
Capturing and non-capturing group
(?<name>…)
Named group
a|b
a or b
(?=…) (?!…)
Followed by, not followed by
(?<=…) (?<!…)
Preceded by, not preceded by
\1 \k<name>
Repeats what a group captured

How it works

How it works

Type a regular expression and some test text: matches are highlighted right away and the table lists each one with its position and capture groups, named groups included ((?<year>\d{4})). Flags are switches; if you paste a literal such as /\d+/gi, the pattern and flags are split for you.

It runs on the browser’s JavaScript engine, so the result is exactly what you get in JS or TS code. Other languages (PCRE, Python, Java) share most of the syntax, but not all of it: JavaScript has no possessive quantifiers, for example.

Replace and errors

The Replace tab lets you try a substitution with $1, $<name> or $& (the whole match) and see the resulting text and how many replacements were made. If the pattern has a syntax error, instead of the technical message you get what is wrong and how to fix it, such as an unclosed parenthesis or a backwards range. The engine’s original message stays folded under “Technical detail”. The collapsible cheat sheet sums up the most common syntax.

↑ ↓ to move, Enter to open, Esc to close

Keyboard shortcuts

Ctrl K/
Search tools
c
Copy the main result
1 … 9
Switch tab
?
Show this help