Skip to content
Developer

Regex Tester

Write a pattern and see what it matches, live. Every match is highlighted in place, capture groups are listed in a table, and a replace preview shows the result.

//g

Press Esc to clear

Replace preview

Cheat sheet
.
Any character except a line break
\d
A digit
\w
A letter, digit or underscore
\s
Any whitespace
\b
A word boundary
^
Start of the string, or of a line with m
$
End of the string, or of a line with m
*
Zero or more of the previous
+
One or more of the previous
?
Zero or one of the previous
{2,5}
Between two and five of the previous
[abc]
Any one of a, b or c
[^abc]
Any character except a, b or c
(…)
A capture group, referenced as $1
(?:…)
A group that does not capture
(?<name>…)
A named capture group
a|b
Either a or b
(?=…)
Followed by, without consuming it
(?!…)
Not followed by

About the Regex Tester

A regular expression is easy to write and hard to be sure about. The difference between a pattern that works and one that works on your three test cases is only visible when you run it against real text, which is what this tool is for: matches are highlighted where they occur, so what the pattern actually captured is visible rather than inferred.

The capture group table is the part that saves the most time. A pattern with several groups produces a numbered list of captured values for each match, along with any named groups, so you can confirm that group 2 really is the part you think it is before writing code that depends on it.

Flags change behaviour more than people expect. The global flag decides whether you get the first match or all of them. Multiline changes what the anchors mean, so that ^ and $ match at each line rather than only at the ends of the whole string — the single most common reason a pattern that looks right finds nothing. The dotAll flag decides whether a dot can match a newline, which matters whenever a pattern spans lines.

One warning worth stating: a regular expression can be written so that it takes exponential time on certain inputs, a failure called catastrophic backtracking. JavaScript has no way to interrupt a running pattern, so the tab simply stops responding. This tool caps the number of matches it will collect, which limits the damage but cannot prevent it — nested quantifiers over a long subject are the shape to be careful with.

Everything runs in your browser.

Frequently asked questions

Why does my pattern not match at the start of each line?

You probably need the multiline flag. Without it, ^ and $ anchor to the start and end of the whole string rather than to each line. It is the most common cause of a pattern that looks correct but finds nothing.

What is catastrophic backtracking?

A pattern whose matching time grows exponentially with input length, usually caused by nested quantifiers. JavaScript cannot interrupt a running regex, so the tab freezes. Match collection is capped here to limit the damage.

Which flavour of regex is this?

JavaScript. Patterns behave exactly as they will in your own JavaScript or TypeScript, which is not identical to PCRE, Python or Go.