Regex Cheatsheet
This cheatsheet provides a comprehensive and practical reference for regular expressions. It covers character classes, anchors, quantifiers, groups, common patterns, command combos, and more. Use it to boost your productivity in pattern matching and text processing.
Regex Cheatsheet
Regular expression patterns and syntax
Patterns
Categories
Favorites
Sections
.Any character except newline
e.g., a.c → abc
\dDigit (0-9)
e.g., \d\d → 42
\DNon-digit
\wWord character (a-z, A-Z, 0-9, _)
\WNon-word character
\sWhitespace
\SNon-whitespace
[abc]Match a, b, or c
[^abc]Match any except a, b, c
[a-z]Lowercase letter range
[A-Z]Uppercase letter range
[0-9]Digit range
[a-zA-Z0-9]Alphanumeric
\\Backslash
\.Literal dot
\*Literal asterisk
\+Literal plus
\?Literal question mark
💡 Escape special regex characters with backslash
^Start of string/line
e.g., ^Hello
$End of string/line
e.g., world$
\bWord boundary
e.g., \bcat\b
\BNon-word boundary
^abc$Exact match 'abc'
^\d+$String of only digits
^[a-z]+$Only lowercase letters
*0 or more
e.g., ab*c → ac, abc, abbc
+1 or more
e.g., ab+c → abc, abbc
?0 or 1 (optional)
e.g., colou?r
{n}Exactly n times
e.g., \d{4}
{n,}n or more times
{n,m}Between n and m times
*?Lazy 0 or more (shortest)
+?Lazy 1 or more
??Lazy 0 or 1
💡 Greedy matches as much as possible; lazy matches as little
(abc)Capture group
(?:abc)Non-capturing group
(?<name>abc)Named capture group
\1Reference to group 1
(?=abc)Positive lookahead
(?!abc)Negative lookahead
(?<=abc)Positive lookbehind
(?<!abc)Negative lookbehind
a|bMatch a or b
(a|b)cGroup alternation
iCase-insensitive
gGlobal (find all)
mMultiline
sDotall (. matches newline)
uUnicode support
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$^https?://[\w.-]+(?:/[\w./-]*)?$URL
^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$Hex color
^\d{4}-\d{2}-\d{2}$Date (YYYY-MM-DD)
^-?\d+$Integer
^-?\d*\.?\d+$Any number
^\d{3}-\d{3}-\d{4}$US phone (123-456-7890)
^\+?[1-9]\d{1,14}$E.164 format
\p{L}Any letter (Unicode)
\p{N}Any number (Unicode)
\p{Emoji}Emoji characters
💡 Requires Unicode flag (/u)
Quick Reference
.
\d
\w
\s
Categories
- Character Classes
Match specific types or ranges of characters, such as digits, letters, or whitespace.
- Anchors
Match positions in the string, such as the start, end, or word boundaries.
- Quantifiers
Specify how many times a pattern should occur.
- Groups & References
Group patterns, capture matches, and use backreferences or lookarounds.
- Common Patterns
Ready-to-use regexes for emails, dates, URLs, numbers, and more.
- Command Combos
Powerful multi-step workflows and advanced usage patterns for real-world scenarios.
Features
- Quick search functionality
- Organized by categories
- Clear pattern descriptions
- Common and advanced use cases covered
- Easy to copy patterns
- Responsive design
- Perfect for quick reference