Skip to content

Regex tester

Write a regular expression and see what it matches as you type, with groups and replace.

Flags

Matches

Cheat sheet

Regular expression basics

PatternMatches
.Any character except a line break
\d \w \sA digit, a word character (letter, digit, _), whitespace
\D \W \SAnything except a digit, word character or whitespace
[abc] [^abc] [a-z]One of a, b, c; anything but those; a range
* + ?Zero or more, one or more, zero or one of the previous item
{3} {2,5}Exactly 3; between 2 and 5
*? +?Lazy: as few as possible
^ $Start and end of the text (or line, with the m flag)
\bA word boundary
(…) (?:…) (?<name>…)Capturing, non-capturing and named groups
a|ba or b
(?=…) (?!…) (?<=…)Lookahead, negative lookahead, lookbehind

Useful patterns

  • Date (YYYY-MM-DD): \d{4}-\d{2}-\d{2}
  • Simple email check: ^[^\s@]+@[^\s@]+\.[^\s@]+$
  • Hex color: #(?:[\da-f]{3}){1,2}\b with the i flag
  • Trailing whitespace on each line: [ \t]+$ with the m flag

Frequently asked questions

Which regex flavor does this use?

JavaScript’s, exactly as in Chrome, Firefox, Safari and Node.js, because it runs on your browser’s own engine. Most syntax is shared with PCRE (PHP), Python and Java, but some features differ, such as lookbehind support in older engines and possessive quantifiers.

What do the flags mean?

g finds every match instead of only the first. i ignores case. m makes ^ and $ match at the start and end of each line. s lets . match line breaks too. u enables full Unicode matching, including \p{L} for any letter.

How do I use capture groups in a replacement?

Refer to numbered groups as $1, $2 and so on, and to named groups as $<name>. $& inserts the whole match. Turn on Replace to try it: the example rewrites 2024-03-10 as 10/03/2024.

Why did my pattern stop with a timeout?

Some patterns, typically nested quantifiers like (a+)+ or (\w*)*, can take exponentially long on text that almost matches. This is called catastrophic backtracking. The tester stops after 1.5 seconds; rewrite the pattern so each character can only be matched in one way.

Is my text sent anywhere?

No. Matching runs in your browser, in a background thread, and nothing is uploaded.