Regex Tester

See what a JavaScript regex matches, group by group, and replace it if you want.

Try this

Highlighted matches

Click Check matches to highlight them here.

$& is the whole match, $1 is the first group, and $<name> is a named group. Click Replace to rewrite the text.

Click Check matches when you're ready.

About Regex Tester

What is a Regex Tester?

You usually open a regex tester for one of three jobs: pull a date out of a log line, check whether a form rule matches, or rewrite a bunch of similar strings in one pass. Paste the pattern and the text, then click Check matches. Nothing is tested while you type.

How to use it:

  1. Type the pattern, or paste one that already looks like /pattern/flags. The flags move into the switches.
  2. Click Check matches. Leave g on to see every match. Turn it off, then check again, when you only care about the first.
  3. Read the groups under the match list. A name like year comes from (?<year>...).
  4. To rewrite the text, type a replacement and click Replace. $1 is the first group, $& is the whole match, and $<name> is a named group.

Tokens worth knowing:

.Any character except a line break. Turn on s if the dot should cross lines.
*The previous piece, zero or more times.
+The previous piece, one or more times.
?Makes the previous piece optional. After * or +, it means “stop as soon as you can.”
[]Any one character from the set. [0-9] is a digit. [^0-9] is everything else.
()A group you can read back as $1, $2, and so on.
|Or. cat|dog matches either word.
\dA digit, 0 through 9.
\wA word character: a letter, a digit, or an underscore.
\sWhitespace: a space, a tab, or a line break.
^ $The start and the end of the text. With m on, they mean the start and end of each line.
(?<name>…)A group you can refer to by name, in the list and as $<name> when you replace.

JavaScript, not PCRE

This page runs the same regex engine as your browser and as Node, not Python and not PCRE. A pattern copied from another language can miss for ordinary reasons: there are no possessive quantifiers such as ++, a replacement uses $1 and $& rather than a backslash and a number, and lookbehind does work in current browsers. If a pattern matches in Python and not here, that difference is the first place to look.

The pattern and the text stay in this tab. Matching does not send them to a server.

Rewriting a blob of text and want to see what changed? Put the before and after into the text diff. If the sample is a JSON payload, the JSON formatter is the easier way to read it before you write a pattern.

Frequently Asked Questions

Does this use JavaScript regex or PCRE?

This uses JavaScript regular expressions, the same kind Chrome, Firefox, Safari, and Node run. It is not PCRE, and it is not Python’s regex. Possessive quantifiers such as ++ are not available. Lookbehind is available in current browsers. When you paste a pattern, write it the way you would in JavaScript: \d is a digit. You do not need to wrap the pattern in slashes unless you want those slashes read as flags.

Why did a group not show up?

A group is only filled in when that part of the pattern took part in the match. If the group is optional, like (\d+)?, and the text matched without it, the list shows that group as not in this match. If the whole pattern missed, there is no match row at all.

What do $1 and $& mean in Replace?

$& means the whole match. $1 means the first pair of capturing parentheses, $2 the second, and so on. $<year> means the group you named year. A backslash followed by 1 does not work in the replacement box. That spelling belongs inside a pattern, not in the replacement.

Why does turning off g change the result?

g means global: every match, not just the first. With it on, Check matches and Replace walk the whole text. With it off, only the first match is listed, and only that one is replaced. Click Check matches again after you change a flag.

Why did it say the pattern is too slow?

Some patterns, usually ones with nested repeats like (a+)+, try the same characters over and over. The tester stops after about a second so the page stays usable. Shorten the text or simplify the pattern and try again.

Is my text uploaded?

No. The match runs in your browser. Typing here does not send the pattern or the text to a server.