Regex Cheat Sheet
Complete regular expression syntax reference with examples. Click any pattern to copy it, or test it directly in our regex tester.
Character Classes
.Any character except newline\dDigit (0-9)Example: 
\d+ matches "123"\DNot a digitExample: 
\D+ matches "abc"\wWord character (a-z, A-Z, 0-9, _)Example: 
\w+ matches "hello_123"\WNot a word characterExample: 
\W+ matches "!@#"\sWhitespace (space, tab, newline)Example: 
\s+ matches "   "\SNot whitespaceExample: 
\S+ matches "hello"[abc]Any of a, b, or cExample: 
[aeiou] matches vowels[^abc]Not a, b, or cExample: 
[^0-9] matches non-digits[a-z]Character range (a to z)Example: 
[a-zA-Z] matches lettersQuantifiers
*Zero or more timesExample: 
a* matches "", "a", "aa"+One or more timesExample: 
a+ matches "a", "aa", not ""?Zero or one time (optional)Example: 
colou?r matches "color" and "colour"{n}Exactly n timesExample: 
\d{3} matches "123"{n,}n or more timesExample: 
\d{3,} matches "123", "1234"{n,m}Between n and m timesExample: 
\d{2,4} matches "12", "123", "1234"*?Lazy match (as few as possible)Example: 
<.*?> matches "<div>"+?Lazy match (one or more)Example: 
a+? matches "a" in "aaa"Anchors & Boundaries
^Start of string or lineExample: 
^hello matches "hello world"$End of string or lineExample: 
world$ matches "hello world"\bWord boundaryExample: 
\bword\b matches "word" not "sword"\BNot a word boundaryExample: 
\Bword\B matches "sword"\AStart of string (multiline mode)Example: 
\Ahello\ZEnd of string (multiline mode)Example: 
world\ZGroups & Capture
(abc)Capturing groupExample: 
(\d{3})-(\d{4}) captures phone(?:abc)Non-capturing groupExample: 
(?:Mr|Ms)\.? matches titles(?<name>abc)Named capturing groupExample: 
(?<year>\d{4})\1Backreference to group 1Example: 
(\w)\1 matches "aa", "bb"(?=abc)Positive lookaheadExample: 
\d(?=px) matches "5" in "5px"(?!abc)Negative lookaheadExample: 
\d(?!px) matches digits not before "px"(?<=abc)Positive lookbehindExample: 
(?<=\$)\d+ matches "5" in "$5"(?<!abc)Negative lookbehindExample: 
(?<!\$)\d+ matches digits not after "$"Flags & Modifiers
gGlobal - find all matchesExample: 
/a/g matches all "a"siCase-insensitiveExample: 
/hello/i matches "Hello"mMultiline - ^ and $ match line breaksExample: 
/^line/msDotAll - . matches newlinesExample: 
/a.b/s matches "a\nb"uUnicode - enable full Unicode supportExample: 
/\u{1F600}/uySticky - match from lastIndexExample: 
/\d/ySpecial Characters
\Escape special characterExample: 
\. matches literal dot|Alternation (OR)Example: 
cat|dog matches "cat" or "dog"\nNewlineExample: 
line1\nline2\rCarriage returnExample: 
\r\n\tTabExample: 
name\tvalue\0Null characterExample: 
\0\xhhHex characterExample: 
\x41 matches "A"\uhhhhUnicode characterExample: 
\u0041 matches "A"Common Patterns
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$Email addressExample: 
user@example.com^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\bURLExample: 
https://example.com^\+?[1-9]\d{1,14}$Phone (international)Example: 
+1234567890^\d{4}-\d{2}-\d{2}$Date (YYYY-MM-DD)Example: 
2025-10-31^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$Hex colorExample: 
#FF5733^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$Password (8+ chars, letter & number)Example: 
Pass1234^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$IPv4 addressExample: 
192.168.1.1^[a-z0-9-]+$URL slugExample: 
my-blog-postTips & Best Practices
Use Non-Capturing Groups
 Use (?:...) when you don't need to capture the match. It's faster and uses less memory. 
Test Your Patterns
Always test regex patterns with real data. Use our Regex Tester to verify before deployment.
Avoid Catastrophic Backtracking
 Be careful with nested quantifiers like (a+)+. They can cause performance issues. 
Use Raw Strings
 In many languages, use raw strings (e.g., Python's r"\d+") to avoid double-escaping backslashes.