Regular expression tester

Type a JavaScript regular expression and some text and see every match highlighted, with the position and each capture group. Try a replacement, and start from a ready-made example.

  • Free
  • No sign-up
  • Runs in your browser
regex-tester
Matches highlighted

100% private — the expression runs in your browser, in a separate worker, and nothing is sent anywhere.

How it works

Type your expression

Or start from one of the examples, such as email, URL or date.

Paste the text to test

Matches are highlighted as you type, with their position and groups.

Try a replacement

Use $1 or $ to rearrange what was captured.

See what your pattern really matches

Regular expressions are compact, powerful and easy to get subtly wrong: a dot that matches too much, a greedy quantifier that swallows half the line, a missing escape. The fastest way to get one right is to try it on real text and see what it catches. This tester highlights every match live, lists the position and the capture groups of each and can also try a replacement, so you can build an expression step by step and see the effect of every change.

What you see

  • Highlighted matches in your text, in alternating colours so that adjacent matches can be told apart. An empty match is shown as a thin bar.
  • A table of matches with the position of each one and its capture groups, numbered and named.
  • The replacement result when you enter a replacement, using $1 for a numbered group, $<name> for a named one and $& for the whole match.
  • The number of matches and the time taken.

Flags

The five checkboxes are the JavaScript flags. g finds all the matches instead of only the first. i ignores upper and lower case. m makes ^ and $ match at the start and end of each line. s lets the dot match line breaks. u turns on full Unicode support, so patterns such as \p{L} for any letter work. Hover over a flag for its meaning.

JavaScript syntax

The tester uses your browser's own regular expression engine, so it follows JavaScript rules: character classes such as \d, \w and \s, anchors, groups, non-capturing groups, lookahead and lookbehind, and named groups. Other languages, such as PCRE in PHP and Perl, Python and Java, are similar but differ in details such as lookbehind rules, flags and some escapes, so test in the target environment before relying on a pattern.

Protection against runaway patterns

Some expressions can take exponentially long on certain text, a problem known as catastrophic backtracking, and could freeze a page. Here the expression runs in a separate worker that is stopped after two seconds, and you are told when that happens, so a bad pattern cannot lock up your browser.

What it does not do

It does not explain the expression in words or generate patterns from examples, and it shows at most the first 2,000 matches. The special characters of the pattern are interpreted as in a JavaScript regex literal, without the slashes. To clean text before matching, use the text cleaner.

Frequently asked questions

How do I test a regular expression?
Type the expression, paste the text to test and see the matches highlighted immediately. Adjust the flags as needed.
How do I see the capture groups?
Each match in the table lists its groups, numbered as $1, $2 and so on, and named groups with their names.
Can I test a replacement?
Yes. Type the replacement text using $1, $2 or $ and the result appears below.
Which regex flavour does it use?
The JavaScript one of your browser. Other languages are similar but may differ in details, so test there too.
What if my expression hangs?
It runs in a worker that is stopped after two seconds, and you get a message. It usually means nested quantifiers that backtrack heavily.
Is my text sent anywhere?
No. Everything runs in your browser.