DevKit Tools

Regex Tester

Test a regular expression against sample text, see every match highlighted with its capture groups, and preview a replacement.

Transform/Regex Tester

Test a regular expression against sample text and see every match, capture group and replacement.

Matches

2 matches

Write to ada@example.com or grace@devkittools.online and we will reply.

Groups in the first match

group 1: ada

group 2: example.com

match 1 at index 9: ada@example.com
  group 1: ada
  group 2: example.com
match 2 at index 28: grace@devkittools.online
  group 1: grace
  group 2: devkittools.online

What the regex tester does

Regular expressions are written by trial and error more often than anyone admits. The fastest way to get one right is to see what it matches as you type, which is what this does: matches are highlighted in place and capture groups are listed separately.

It also runs the replacement, so you can confirm that $1 and $2 land where you expect before putting the pattern anywhere important.

Watch the capture groups as closely as the matches. Most regex bugs are not about whether something matches but about what ends up in which group, and a group that grabs the wrong slice is what quietly breaks the replacement or the code reading it downstream.

Good to know

  • Anchor when you mean to. ^ and $ tie a match to the start and end; without them a pattern meant to validate a whole string will happily match a valid fragment buried in invalid input.
  • A dot does not match a newline unless the s flag is set. A pattern that works on one line and fails across several is almost always missing it.
  • Reach for a non-greedy quantifier when a greedy one overshoots. .* grabs as much as it can and often swallows past where you wanted; .*? stops at the first chance instead.

Using the tool

  1. 1Enter your pattern, without the surrounding slashes.
  2. 2Set the flags: g for all matches, i to ignore case, m for multiline.
  3. 3Paste text to test against.
  4. 4Read the highlighted matches and the capture groups below.
  5. 5Add a replacement string to see the transformed result.
  6. 6Copy the ready made JavaScript.

Common questions

Which regex flavour is this?

JavaScript's, which is what runs in every browser and in Node. It is close to PCRE but not identical: lookbehind is supported in modern browsers, and there are no possessive quantifiers or recursion.

What do the flags do?

g finds every match instead of stopping at the first, i ignores case, m makes ^ and $ match at line breaks, s lets the dot match newlines, and u enables full unicode handling.

Why does my pattern hang the page?

Nested quantifiers such as (a+)+ can backtrack catastrophically on input that nearly matches. Rewrite the pattern to avoid nesting a quantifier inside another.

How do I use capture groups in the replacement?

Use $1 for the first group, $2 for the second, and $& for the whole match. Named groups use $<name>.

Why does $ not match where I expect?

Without the m flag, $ matches only at the very end of the input, not at each line break. Add m to make ^ and $ work per line.

Try next

More Text & Data tools