Regex Cheat Sheet
Complete regex reference with syntax, examples, and common patterns. Searchable and filterable.
Live Tester
Showing 54 of 54 entries
Anchors
PatternNameDescriptionExample
Start of string
Match at the beginning of the string
^Hello matches 'Hello world'
End of string
Match at the end of the string
world$ matches 'Hello world'
Word boundary
Match at a word boundary
\bword\b matches 'word' but not 'password'
Non-word boundary
Match where \b would not match
\Bword\B matches 'password'
Character Classes
PatternNameDescriptionExample
Any character
Match any single character except newline
a.c matches 'abc', 'axc', 'a1c'
Digit
Match any digit [0-9]
\d+ matches '123' in 'abc123'
Non-digit
Match any non-digit character
\D+ matches 'abc' in 'abc123'
Word character
Match [a-zA-Z0-9_]
\w+ matches 'hello_123'
Non-word character
Match any non-word character
\W matches space, comma, etc.
Whitespace
Match space, tab, newline, etc.
\s+ matches all whitespace
Non-whitespace
Match any non-whitespace character
\S+ matches 'hello'
Character set
Match any character in the set
[aeiou] matches any vowel
Negated set
Match any character NOT in the set
[^aeiou] matches any consonant
Character range
Match any character in the range
[a-z] matches any lowercase letter
Case-insensitive range
Match any letter upper or lower
[a-zA-Z]+ matches words
Quantifiers
PatternNameDescriptionExample
Zero or more
Match 0 or more of the preceding
ab* matches 'a', 'ab', 'abb'
One or more
Match 1 or more of the preceding
ab+ matches 'ab', 'abb' but not 'a'
Zero or one
Match 0 or 1 of the preceding (optional)
colou?r matches 'color' and 'colour'
Exactly n
Match exactly n of the preceding
\d{3} matches exactly 3 digits
At least n
Match n or more of the preceding
\d{2,} matches 2 or more digits
Between n and m
Match between n and m of the preceding
\d{2,4} matches 2-4 digits
Lazy zero or more
Match as few as possible (non-greedy)
<.*?> matches individual tags
Lazy one or more
Match as few as possible (non-greedy)
a+? matches 'a' in 'aaa'
Groups & References
PatternNameDescriptionExample
Capture group
Group and capture match for backreference
(\w+)\s\1 matches 'the the'
Non-capture group
Group without capturing
(?:foo|bar)+ matches 'foobar'
Named capture group
Capture with a named reference
(?<year>\d{4}) captures year
Backreference
Reference first captured group
(\w+) \1 matches repeated words
Lookahead
Match only if followed by abc
\d(?= dollars) matches digit before ' dollars'
Negative lookahead
Match only if NOT followed by abc
\d(?! dollars) matches digits not before ' dollars'
Lookbehind
Match only if preceded by abc
(?<=\$)\d+ matches digits after $
Negative lookbehind
Match only if NOT preceded by abc
(?<!\$)\d+ matches digits not after $
Alternation
PatternNameDescriptionExample
Alternation
Match a or b
cat|dog matches 'cat' or 'dog'
Flags
PatternNameDescriptionExample
Global
Find all matches, not just the first
/\d/g finds all digits
Case-insensitive
Match regardless of case
/hello/i matches 'Hello', 'HELLO'
Multiline
^ and $ match start/end of lines
/^\d/m matches digits at line start
Dot all (dotAll)
Dot (.) matches newline too
/a.b/s matches 'a\nb'
Unicode
Enable full Unicode support
/\u{1F600}/u matches emoji
Global + case-insensitive
Common combination
/word/gi finds all case variations
Escape & Special
PatternNameDescriptionExample
Newline
Match a newline character
line1\nline2
Tab
Match a tab character
col1\tcol2
Carriage return
Match a carriage return
Windows line endings: \r\n
Literal backslash
Match a backslash character
C:\\Users matches 'C:\Users'
Literal dot
Match a literal period
file\.txt matches 'file.txt'
Literal asterisk
Match a literal asterisk
v1\.\* matches 'v1.*'
Common Patterns
PatternNameDescriptionExample
URL
Match http/https URLs
https://devpick.sh/tools
ISO date (YYYY-MM-DD)
Match ISO 8601 date format
2024-01-15
Phone number
Basic international phone number
+1 (555) 123-4567
Hex color
Match 3 or 6 char hex colors (no #)
3b82f6 or ff5733
Strong password
Min 8 chars, uppercase, lowercase, digit
MyPass123
IPv4 address
Match valid IPv4 addresses
192.168.1.1
URL slug
Lowercase letters, digits, hyphens
my-awesome-article-123
CSS hex color
Match CSS hex color with optional #
#3b82f6 or #fff
Formatted number
Match numbers like 1,234.56
1,234.56 or 1,000,000