← All Tools

🔍 Regex Cheat Sheet

Regular expression quick reference — 67+ patterns

Showing all patterns

Basic Patterns

.
Match any character except newline
\d
Match any digit [0-9]
\D
Match any non-digit
\w
Match word character [a-zA-Z0-9_]
\W
Match non-word character
\s
Match whitespace (space, tab, newline)
\S
Match non-whitespace
\b
Word boundary
\B
Not a word boundary
^
Start of string/line
$
End of string/line

Quantifiers

a*
Zero or more of 'a'
a+
One or more of 'a'
a?
Zero or one of 'a'
a{3}
Exactly 3 of 'a'
a{3,}
3 or more of 'a'
a{3,5}
Between 3 and 5 of 'a'
a*?
Zero or more (lazy/non-greedy)
a+?
One or more (lazy/non-greedy)
a??
Zero or one (lazy/non-greedy)

Character Classes

[abc]
Match 'a', 'b', or 'c'
[^abc]
Match anything except 'a', 'b', 'c'
[a-z]
Match any lowercase letter
[A-Z]
Match any uppercase letter
[0-9]
Match any digit
[a-zA-Z0-9]
Match any alphanumeric character
[\s\S]
Match any character (including newline)

Groups & References

(abc)
Capturing group
(?:abc)
Non-capturing group
(?P<name>abc)
Named capturing group (Python)
(?<name>abc)
Named capturing group (JS/C#)
\1
Back-reference to group 1
(a|b)
Match 'a' or 'b'
(?>abc)
Atomic group (no backtracking)

Lookahead & Lookbehind

(?=abc)
Positive lookahead — followed by 'abc'
(?!abc)
Negative lookahead — NOT followed by 'abc'
(?<=abc)
Positive lookbehind — preceded by 'abc'
(?<!abc)
Negative lookbehind — NOT preceded by 'abc'

Flags / Modifiers

i
Case-insensitive matching
g
Global (find all matches)
m
Multiline (^ and $ match line boundaries)
s
Dotall (. matches newline too)
x
Verbose (allow comments and whitespace)
u
Unicode matching

Common Patterns

^\S+@\S+\.\S+$
Email (basic)
^https?://[\S]+$
URL (basic)
^\d{4}-\d{2}-\d{2}$
Date (YYYY-MM-DD)
^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$
IPv4 address
^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$
Hex color code
^\+?\d{10,15}$
Phone number (international)
^(?=.*[A-Z])(?=.*[a-z])(?=.*\d).{8,}$
Password (8+ chars, upper+lower+digit)
^-?\d+(\.\d+)?$
Number (integer or decimal)
<[^>]+>
HTML tag
(\w+)\s+\1
Repeated word

JavaScript Usage

/pattern/.test("string")
Test if matches
"string".match(/pattern/g)
Find all matches
"string".replace(/old/g, "new")
Replace all occurrences
"string".split(/pattern/)
Split by pattern
new RegExp('pattern', 'gi')
Dynamic regex from string

Python Usage

import re
Import regex module
re.search(r"pattern", text)
Find first match
re.findall(r"pattern", text)
Find all matches
re.sub(r"old", "new", text)
Replace pattern
re.split(r"pattern", text)
Split by pattern
re.compile(r"pattern")
Compile for reuse
match.group(0)
Full match text
match.group(1)
First capture group
\xF0\x9F\x92\x99 Tip\xF0\x9F\x93\x9A Get Bundle \x244.99