appzasGamesToolsDevLearnCheat sheetsQuick calcsConvertersReferenceNetworkTimeCalculatorsCompareLLM prices

Regex cheat sheet

Free and printable

Syntax that works in JavaScript, Python, PCRE and most other engines. Test patterns with the regex tester.

Characters

.
Any character except newline
\d \w \s
Digit, word character, whitespace
\D \W \S
The opposites
[abc]
One of a, b or c
[a-z0-9]
A range
[^abc]
Anything except a, b or c
\.
A literal dot (escape special characters)

Quantifiers

*
Zero or more
+
One or more
?
Zero or one
{3}
Exactly 3
{2,4}
Between 2 and 4
+? *?
Lazy versions: as few as possible

Anchors

^
Start of the text (or line with the m flag)
$
End of the text (or line)
\b
Word boundary

Groups

(abc)
Capture group
(?:abc)
Group without capturing
(?<name>abc)
Named group (Python: (?P<name>abc))
a|b
a or b
\1
Reuse the first captured group

Lookaround

(?=x)
Followed by x
(?!x)
Not followed by x
(?<=x)
Preceded by x
(?<!x)
Not preceded by x

Flags

i
Ignore case
g
All matches (JavaScript)
m
^ and $ match at each line
s
Dot also matches newline

Common patterns

^\d{5}$
US ZIP code (5 digits)
^\d{4}-\d{2}-\d{2}$
Date like 2026-10-04 (format only, not validity)
^[^@\s]+@[^@\s]+\.[^@\s]+$
Simple email shape check
^#?[0-9a-fA-F]{6}$
Hex color
^\s+|\s+$
Leading or trailing whitespace

More cheat sheets