Regex Cheat Sheet
Complete regular expression syntax reference with patterns and examples.
Character Classes
.Any character except newline\wWord character [a-zA-Z0-9_]\WNon-word character\dDigit [0-9]\DNon-digit\sWhitespace (space, tab, newline)\SNon-whitespace[abc]Character class β a, b, or c[^abc]Negated class β not a, b, or c[a-z]Range β any lowercase letter[a-zA-Z0-9]Alphanumeric charactersAnchors
^Start of string (or line with multiline)$End of string (or line with multiline)\bWord boundary\BNon-word boundary\AStart of string (not multiline)\ZEnd of string (not multiline)Quantifiers
*Zero or more (greedy)+One or more (greedy)?Zero or one (greedy){n}Exactly n times{n,}n or more times{n,m}Between n and m times*?Zero or more (lazy/non-greedy)+?One or more (lazy/non-greedy)??Zero or one (lazy/non-greedy)Groups & Alternation
(abc)Capture group(?:abc)Non-capturing group(?P<name>abc)Named capture groupa|bAlternation β a or b(?=abc)Positive lookahead(?!abc)Negative lookahead(?<=abc)Positive lookbehind(?<!abc)Negative lookbehindEscapes & Special
\nNewline\tTab\rCarriage return\0Null character\uXXXXUnicode character (hex)\.Literal dot (escaped)\\Literal backslashFlags
gGlobal β find all matchesiCase-insensitivemMultiline β ^ and $ match line start/endsDotall β . matches newlineuUnicode β treat pattern as UnicodeySticky β match from lastIndexCommon Patterns
^[\w.-]+@[\w.-]+\.\w{2,}$Email addresshttps?://[\w./%-]+URL (basic)^\d{1,3}(\.\d{1,3}){3}$IPv4 address^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$Hex color^\d{4}-\d{2}-\d{2}$ISO date (YYYY-MM-DD)^[+]?[\d\s()-]{7,15}$Phone number (basic)^(?=.*[A-Z])(?=.*\d).{8,}$Password: 8+ chars, 1 uppercase, 1 digit