Regex Tester

Test regular expressions with real-time match highlighting, capture groups, and replace mode.

/ /
Enter a pattern and test string to see results.
Regex Quick Reference

Character Classes

\ddigit0-9
\wworda-z, A-Z, 0-9, _
\swhitespacespace, tab, newline
.any charexcept newline
\DNOT digitnegation of \d
\WNOT wordnegation of \w
\SNOT whitespacenegation of \s
[abc]character setmatch a, b, or c
[^abc]negated setNOT a, b, or c
[a-z]rangea through z

Quantifiers

*0 or moregreedy
+1 or moregreedy
?0 or 1optional
{n}exactly ne.g. {3}
{n,}n or moree.g. {2,}
{n,m}n to me.g. {1,3}
*?lazymatch as few as possible
+?lazymatch as few as possible

Anchors

^startbeginning of line
$endend of line
\bword boundarybetween \w and \W
\Bnot boundarynegation of \b

Groups & Lookarounds

(abc)capture groupcaptures match
(?:abc)non-capturinggroups without capture
|alternationOR, e.g. cat|dog
\1backrefrefers to group 1
(?=...)lookaheadfollowed by ...
(?!...)negative lookaheadNOT followed by ...
(?<=...)lookbehindpreceded by ...
(?<!...)negative lookbehindNOT preceded by ...

Common Examples

^\w+@\w+\.\w+$Email
^\d{3}-\d{4}$Phone (xxx-xxxx)
^#[0-9a-fA-F]{6}$Hex color
^\d{4}-\d{2}-\d{2}$Date (YYYY-MM-DD)
^https?://[\w.-]+URL
^\d{17}[\dXx]$Chinese ID number