Regex Tester
Test a regular expression against sample text, see every match highlighted with its capture groups, and preview a replacement.
Test a regular expression against sample text and see every match, capture group and replacement.
Matches
2 matches
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.onlineAbout the regex tester
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.
How to use it
- 1Enter your pattern, without the surrounding slashes.
- 2Set the flags: g for all matches, i to ignore case, m for multiline.
- 3Paste text to test against.
- 4Read the highlighted matches and the capture groups below.
- 5Add a replacement string to see the transformed result.
- 6Copy the ready made JavaScript.
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>.