Regex Cheat Sheet

Quick reference for regular expression syntax. Character classes, quantifiers, anchors, groups, lookaheads, and common patterns — all in one page.

Character Classes Anchors Quantifiers Groups & References Lookahead & Lookbehind Flags Common Patterns

Character Classes

. Any character except newline
\d Digit (0-9)
\D Not a digit
\w Word character (a-z, A-Z, 0-9, _)
\W Not a word character
\s Whitespace (space, tab, newline)
\S Not whitespace
[abc] Any of a, b, or c
[^abc] Not a, b, or c
[a-z] Any character from a to z

Anchors

^ Start of string (or line with m flag)
$ End of string (or line with m flag)
\b Word boundary
\B Not a word boundary

Quantifiers

* 0 or more
+ 1 or more
? 0 or 1 (optional)
{3} Exactly 3
{3,} 3 or more
{3,5} Between 3 and 5
*? 0 or more (lazy)
+? 1 or more (lazy)

Groups & References

(abc) Capture group
(?:abc) Non-capturing group
(?abc) Named capture group
\1 Backreference to group 1
a|b Alternation (a or b)

Lookahead & Lookbehind

(?=abc) Positive lookahead
(?!abc) Negative lookahead
(?<=abc) Positive lookbehind
(? Negative lookbehind

Flags

g Global — find all matches
i Case-insensitive
m Multiline — ^ and $ match line start/end
s Dotall — . matches newline
u Unicode support

Common Patterns

^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,}$ Email (basic)
^https?:\/\/[\w.-]+\.[a-zA-Z]{2,} URL
^\d{1,3}(\.\d{1,3}){3}$ IPv4 address
^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$ Hex color
^\d{4}-\d{2}-\d{2}$ Date (YYYY-MM-DD)
^\+?\d{10,15}$ Phone number (international)

Try It Live

Test these patterns with our free Regex Tester. No signup needed.

Open Regex Tester →
Step-by-Step Guide

How to Test Regex Online

Read Guide →

More Cheat Sheets