Regex Cheat Sheet
Interactive regex reference with syntax groups, quick-copy patterns, and live examples for common use cases.
Character Classes
.Matches any single character except newline
a.c matches "abc", "a1c"
\dMatches any digit (0-9)
\d+ matches "123" in "abc123"
\DMatches any non-digit character
\D+ matches "abc" in "abc123"
\wMatches any word character (a-z, A-Z, 0-9, _)
\w+ matches "hello_1"
\WMatches any non-word character
\W matches "!" in "hello!"
\sMatches any whitespace (space, tab, newline)
\s matches " " in "a b"
\SMatches any non-whitespace character
\S+ matches "hello"
[abc]Matches any character in the set
[aeiou] matches "e" in "hello"
[^abc]Matches any character not in the set
[^aeiou] matches "h" in "hello"
[a-z]Matches any character in the range
[a-f] matches "c" in "cat"
Anchors
^Matches start of string or line
^Hello matches "Hello world"
$Matches end of string or line
world$ matches "Hello world"
\bMatches a word boundary position
\bcat\b matches "cat" not "catch"
\BMatches a non-word boundary position
\Bcat matches "cat" in "scat"
Quantifiers
*Matches zero or more of the preceding element
ab*c matches "ac", "abc", "abbc"
+Matches one or more of the preceding element
ab+c matches "abc", "abbc" not "ac"
?Matches zero or one of the preceding element
colou?r matches "color", "colour"
{n}Matches exactly n of the preceding element
\d{3} matches "123" not "12"
{n,}Matches n or more of the preceding element
\d{2,} matches "12", "123", "1234"
{n,m}Matches between n and m of the preceding element
\d{2,4} matches "12", "123", "1234"
*?Matches as few characters as possible (lazy)
<.*?> matches "<b>" in "<b>text</b>"
Groups & Lookaround
(...)Captures the matched group for back-references
(abc)+ matches "abcabc"
(?:...)Groups without capturing the match
(?:abc)+ groups without capture
(?=...)Positive lookahead: matches if followed by pattern
\d(?=px) matches "5" in "5px"
(?!...)Negative lookahead: matches if NOT followed by pattern
\d(?!px) matches "5" in "5em"
(?<=...)Positive lookbehind: matches if preceded by pattern
(?<=\$)\d+ matches "50" in "$50"
(?<!...)Negative lookbehind: matches if NOT preceded by pattern
(?<!\$)\d+ matches "50" in "50"
\1Matches the same text as previously matched by group n
(\w)\1 matches "ll" in "hello"
|Matches the pattern before or after the pipe
cat|dog matches "cat" or "dog"
Flags
gFind all matches, not just the first
/a/g finds all "a" in "banana"
iCase-insensitive matching
/hello/i matches "Hello", "HELLO"
m^ and $ match start/end of each line
/^abc/m matches at each line start
sDot (.) also matches newline characters
/a.b/s matches "a\nb"
uEnable full Unicode matching
/\u{1F600}/u matches emoji
Common Patterns
[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}Email address pattern
user@example.com
https?://[\w.-]+(?:\.[\w.-]+)+[\w.,@?^=%&:/~+#-]*URL with protocol pattern
https://example.com/path
\b\d{1,3}(?:\.\d{1,3}){3}\bIPv4 address pattern
192.168.1.1
\+?[\d\s()-]{7,15}Phone number pattern (international)
+1 (555) 123-4567
\d{4}-\d{2}-\d{2}ISO date format (YYYY-MM-DD)
2026-03-23
#?[0-9a-fA-F]{3,8}Hex color code pattern
#ff6600, #f60
\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}Credit card number pattern (16 digits)
4111 1111 1111 1111
[a-z0-9]+(?:-[a-z0-9]+)*URL slug pattern (lowercase, hyphenated)
my-blog-post-title
[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}UUID v4 pattern
550e8400-e29b-41d4-a716-446655440000
<([a-zA-Z][a-zA-Z0-9]*)\b[^>]*>.*?</\1>HTML tag with content pattern
<div class="x">text</div>
Learn More
A searchable reference covering character classes, quantifiers, anchors, groups, and lookarounds. Find the regex syntax you need in seconds.
Why Every Developer Needs a Regex Quick Reference
Regular expressions are one of the most powerful tools in a developer's toolkit, yet they remain notoriously hard to memorize. Whether you are validating user input, parsing log files, or performing search-and-replace operations across a codebase, regex patterns can save hours of manual work. The problem is that the syntax is dense -- a single misplaced quantifier or forgotten escape can break an entire pattern.