Regex Cheat Sheet — Complete Regular Expression Reference

Everything you need to know about regex syntax in one page. Character classes, anchors, quantifiers, groups, lookaheads, lookbehinds, and flags. Click any example to load it into the tester.

The Essential Regex Elements

Regular expressions are built from a small set of core elements. Character classes like \d (digits) and \w (word characters) match categories of characters. Anchors like ^ and $ match positions, not characters. Quantifiers like + and * control repetition. Combined, these build patterns from simple to complex.

JavaScript-Specific Features

JavaScript's regex engine includes modern features: named groups (?<name>...) for readable captures, lookbehind (?<=...) for matching based on preceding context, the s flag making . match newlines, and Unicode property escapes \p{Script=Greek} with the u flag.

Interactive Learning

This isn't just a static reference — every example in the cheat sheet is clickable. Click a row to load its pattern and sample text into the tester above. Modify the pattern or text to experiment. This makes it easy to learn regex by doing, not just reading.

Browse the cheat sheet below and click any example to test it.

/
/g
✅ Valid pattern
No matches

Regex Cheat Sheet

Characters

PatternDescriptionExample
.Any character (except newline)a.c
\dAny digit (0-9)\d{3}
\DAny non-digit\D+
\wWord character (a-z, A-Z, 0-9, _)\w+
\WNon-word character\W
\sWhitespace (space, tab, newline)\s+
\SNon-whitespace\S+

Anchors

PatternDescriptionExample
^Start of string/line^Hello
$End of string/lineworld$
\bWord boundary\bcat\b
\BNon-word boundary\Bcat\B

Quantifiers

PatternDescriptionExample
*Zero or moreab*c
+One or moreab+c
?Zero or one (optional)colou?r
{n}Exactly n times\d{3}
{n,}n or more times\d{2,}
{n,m}Between n and m times\d{2,4}
*?, +?Lazy (as few as possible)<.+?>

Groups & References

PatternDescriptionExample
(abc)Capturing group(\w+)@(\w+)
(?:abc)Non-capturing group(?:ab)+
(?<name>abc)Named capturing group(?<year>\d{4})
\1, \2Back-reference to group(\w+) \1
(?=abc)Positive lookahead\d+(?= dollars)
(?!abc)Negative lookahead\d+(?! dollars)
(?<=abc)Positive lookbehind(?<=\$)\d+
(?<!abc)Negative lookbehind(?<!\$)\d+

Character Classes

PatternDescriptionExample
[abc]Match a, b, or c[aeiou]
[^abc]Match anything except a, b, c[^aeiou]
[a-z]Match any lowercase letter[a-z]+
[A-Z]Match any uppercase letter[A-Z]+
[0-9]Match any digit[0-9]+
[a-zA-Z0-9]Match any alphanumeric[a-zA-Z0-9]+

Flags

PatternDescription
gGlobal — find all matches
iCase insensitive
mMultiline — ^ and $ match line boundaries
sDotAll — . matches newlines
uUnicode support
ySticky — match from lastIndex

Click any row with an example to load it into the tester above.