Developer Patterns

Regex tester

What to do
global. Find every match, not just the first
Result
Write to [email protected] or [email protected] before Friday.

2 matches

9 [email protected] $1=ada $2=example.com
28 [email protected] $1=grace $2=example.org
What the pattern says
( start of a capturing group
\w a word character — letter, digit or underscore
+ the thing before it, one or more times
) end of the group
@ matched literally
( start of a capturing group
\w a word character — letter, digit or underscore
+ the thing before it, one or more times
\. a literal .
\w a word character — letter, digit or underscore
{2,} the thing before it, 2 or more times
) end of the group
A reading aid, piece by piece, not a full parse.

Runs in your browser · nothing is uploaded

Local · the browser’s own engine

Type a pattern and it runs against your text as you type: matches highlighted in place, capture groups listed with their positions, and a plain-English reading of what each piece of the pattern does. Replace and split are the same pattern applied a different way, and Escape a literal runs the other direction: text in, every metacharacter backslashed, ready to drop into a pattern.

How to use the regex tester

1 Type the pattern between the slashes. Do not include the slashes themselves.
2 Turn flags on and off. G finds every match rather than the first.
3 Paste the text you are testing against. Matches highlight immediately.
4 Switch to Replace to try a substitution, or Split to cut the text on the pattern.
5 Switch to Escape a literal for the other direction: paste text that has to match itself and take back the version with every metacharacter escaped.

This uses the browser’s own regular-expression engine, which is the same one your JavaScript will run against, so a pattern that works here works in your code, and one that does not will not. That is worth knowing because regex flavours genuinely differ: lookbehind, \p{…} properties and named groups all behave differently in PCRE, Python and POSIX, and a pattern copied from a PHP answer may simply not compile here.

One pattern shape is refused rather than run. A quantifier nested inside a quantified group: (a+)+, (\d+)*. Can take exponential time on input that nearly matches, and because the engine runs on the same thread as the page there is no way to interrupt it: the tab stops responding and the only fix is closing it. Rather than let that happen, the pattern is rejected with an explanation. The fix is almost always to make the inner quantifier possessive in spirit: match a specific character class instead of nesting repetition.

The explanation panel walks the pattern and names each piece. It is a reading aid, not a parser: it does not build a tree or tell you what the pattern means as a whole, and it will not catch a logic error. It is there for the case everyone actually has, which is inheriting a pattern from a colleague and needing to know what (?<=\s) was for.

Twelve characters carry meaning inside a pattern and have to be escaped with a backslash to match themselves: . * + ? ^ $ { } ( ) | [ ], along with the backslash, the forward slash where a pattern is written between slashes, and the hyphen inside a character class, where an unescaped one means a range. That is worth more than convenience. Building a pattern by concatenating user input is the regex equivalent of building SQL by concatenation: a search box that drops what someone typed into a new RegExp can be handed (a+)+$ and made to hang the process, which is the same shape this tester refuses. RegExp.escape reached browsers only recently, which is why nearly every codebase still carries its own copy of the same one-line function: s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), a backslash in front of every character that would otherwise mean something. Escape a literal, above, is that function with a box around it: paste the text that has to match itself and take the escaped form out. Use the panel when you are assembling a pattern by hand, and the line when the escaping has to happen at runtime in your own code.

What people use it for

  • Checking a pattern against real text before it goes near production
  • Reading a pattern someone else wrote
  • Testing a replacement with capture groups in it
  • Splitting a line on a pattern to see what falls out
  • Escaping a literal string so it can go into a pattern and match itself
  • Working out why a match is longer than expected

Questions

Yes, it is the browser’s own RegExp. A pattern that works here works in your code.

MDN, Regular expressionsECMA-262, RegExp objects
Was this tool any good?
Internal signal only · I use it to find the tools worth rebuilding