Regex Tester

Test a regular expression and see every match as you type.

Matches: 2
Contact us at hello@example.com or support@test.com.
Not an email: user@localhost
#Match$1$2
1hello@example.comhelloexample
2support@test.comsupporttest

How to test a regex

  1. Type the pattern without the surrounding slashes.
  2. Choose flags and paste the text to search.
  3. Check the highlighted matches and groups, and try a replacement.

Building blocks

\d is a digit, \w a word character, \s whitespace, . any character, ^ and $ the start and end. Quantifiers * + ? and {n,m} set how many times, and parentheses create groups.

Greedy and lazy

By default .* matches as much as possible. Add ? (.*?) to match as little as possible, for example to take one HTML tag at a time instead of everything between the first < and the last >.

Write patterns that stay fast

Avoid nested quantifiers like (a+)+ and overlapping alternatives, anchor patterns with ^ and $ when you can, and prefer specific classes like [^"]* over .*.

Frequently asked questions

Which regex flavor is used?

JavaScript (ECMAScript), the same engine as your browser and Node.js. Most syntax also works in Python, Java and PCRE, with small differences.

How do I reference groups in the replacement?

Use $1, $2 for numbered groups, $<name> for named groups and $& for the whole match.

Why does my pattern only match once?

Without the g (global) flag, only the first match is found.

Why did the page freeze?

Some patterns with nested quantifiers, like (a+)+, take exponential time on certain input. Simplify the pattern or make it more specific.