Regex Tester

Enter a pattern, toggle flags and paste your text: every match is highlighted as you type, with its position and capture groups. Switch to Replace to preview substitutions, or start from a common pattern.

Loading Regex Tester…

How to Use Regex Tester

1

Write or insert a pattern

Type a regular expression, or pick a common pattern such as an email address, URL or ISO date from the insert menu to start from.

2

Set the flags

Turn on g, i, m, s, u or y as needed. Hover a flag to see what it does.

3

Paste your test text

Matches are highlighted as you type, and the match list shows each match with its position and capture groups.

4

Try a replacement

Switch to replace mode and enter a replacement using $1 or $<name> to refer to groups, then copy the replaced text.

Regex Tester Guide

How the tester works

Patterns run on your browser's JavaScript regex engine, so results match what RegExp, String.match() and String.replace() will do in your code. The g, i, m, s, u and y flags are supported. Matches are highlighted in the text and listed with their starting index and every capture group, including named groups such as (?<year>\d{4}), up to 1,000 matches. Replace mode previews String.replace() output, with $1, $<name> and $& substitutions.

Most regex syntax is shared across JavaScript, Python, Java, Go and PCRE, but details differ: lookbehind support, named group syntax and Unicode classes vary. Check against your target language for anything beyond the basics.

Flags at a glance

g finds every match instead of stopping at the first. i ignores case. m makes ^ and $ match at the start and end of each line. s lets . match newlines. u turns on full Unicode handling, including \p{L} style property classes. y (sticky) only matches at the exact position where the last match ended.

Patterns worth knowing

\d+ matches runs of digits. ^\s+|\s+$ finds leading and trailing whitespace. \b\w+@\w+\.\w+\b is a rough email matcher, good for searching logs but not for validation. (\d{4})-(\d{2})-(\d{2}) captures the year, month and day of an ISO date as three groups. Prefer specific character classes over .* wherever you can; greedy wildcards are the most common source of surprising matches.

Frequently Asked Questions

Which regex flavor does this tester use?

It uses the JavaScript engine built into your browser, the same one used by Node.js and every browser. Most syntax works the same in Python, Java, .NET and PCRE, but lookbehind support, named group syntax and some Unicode features differ, so test patterns in your target language too.

Why does my pattern only find the first match?

Without the g flag, JavaScript stops after the first match. Turn on g to find every match. When you call replace() in code without g, only the first occurrence is replaced, which is a common source of bugs.

What is the difference between greedy and lazy quantifiers?

A greedy quantifier such as .* matches as much text as possible, while a lazy one such as .*? matches as little as possible. On "<b>one</b><b>two</b>", the pattern <b>.*</b> matches the whole string, while <b>.*?</b> matches each tag pair separately.

Should I validate email addresses with a regex?

Use a simple pattern to catch obvious typos, such as one requiring text, an @ and a dot in the domain. Fully correct email validation by regex is impractical, and overly strict patterns reject valid addresses. The reliable check is sending a confirmation email.

More in Developer Utilities