Regex Cheatsheet Lookup
Searchable reference for 100+ regex tokens with live examples, common pattern library, inline tester, and cross-flavor notes for JS, Python, PCRE, POSIX.
Share:
Regex Cheatsheet Lookup
Searchable reference for 100+ regex tokens with live examples, common pattern library, inline tester, and cross-flavor notes for JavaScript, Python, PCRE, and POSIX.
68 tokens
14 common patterns
4 flavors
Character Classes13
Any digit (0-9).
\d+→Order #12345 on 2024
\d→abc 7 xyz
Any non-digit character.
\D+→123abc456
Any word character (a-z, A-Z, 0-9, _).
\w+→hello_world!
Any non-word character.
\W→hi!
Any whitespace (space, tab, newline).
a\sb→a b
Any non-whitespace character.
\S+→ hello
Any character except newline (unless s flag is set).
h.t→hat hot hit
Character set — matches any one of a, b, or c.
[aeiou]→hello
Negated character set — any char except a, b, or c.
[^aeiou]+→hello
Character range — any lowercase letter.
[a-z]+→ABC xyz 123
Any uppercase letter.
[A-Z]+→Hello World
Any digit (same as \d in ASCII mode).
[0-9]{3}→tel 555 ok
Any alphanumeric character.
[a-zA-Z0-9]+→_abc123_
Anchors & Boundaries7
Start of string (or line with m flag).
^Hello→Hello world
End of string (or line with m flag).
world$→Hello world
Word boundary.
\bcat\b→the cat sat
Non-word boundary.
\Bcat→concatenate
Start of input (PCRE/Python — not JS).
\AHello→Hello world
End of input (PCRE/Python — not JS).
world\Z→Hello world
Absolute end of string (PCRE).
end\z→the end
Quantifiers11
Zero or more (greedy).
ab*→a abbb
One or more (greedy).
ab+→a abbb
Zero or one (optional).
colou?r→color
Exactly n times.
\d{4}→year 2024
n or more times.
\d{2,}→1 22 333
Between n and m times.
\d{2,4}→12345
Lazy zero or more — matches as few as possible.
<.*?>→<b>hi</b>
Lazy one or more.
\d+?→12345
Lazy optional.
ab??→ab
Lazy bounded quantifier.
\d{2,4}?→12345
Possessive quantifier (PCRE) — no backtracking.
a*+b→aaab
Groups & Lookarounds10
Capturing group.
(\d+)-(\d+)→2024-04
Non-capturing group.
(?:ab)+→ababab
Named capturing group.
(?<year>\d{4})→year 2024
Backreference to group 1.
(\w)\1→letter
Named backreference.
(?<q>["']).*?\k<q>→"hi"
Positive lookahead — followed by abc.
\d+(?=px)→10px 20em
Negative lookahead — not followed by abc.
\d+(?!px)→10em 20px
Positive lookbehind — preceded by abc.
(?<=\$)\d+→price $99
Negative lookbehind — not preceded by abc.
(?<!\$)\d+→100 $99
Atomic group (PCRE) — no backtracking.
(?>a+)b→aaab
Alternation2
Alternation — matches left OR right.
cat|dog→I have a dog
Grouped alternation.
(red|green|blue)→sky is blue
Escapes & Special Characters9
Literal dot.
\.com→site.com
Literal forward slash (needed in /.../ syntax).
\/api→/api/v1
Literal backslash.
\\n→path\name
Newline character.
a\nb→a
b
Tab character.
\t+→a b
Carriage return.
\r\n→line
Null character.
\0→