Regular Expressions (Regex) Cheat Sheet & Pattern Reference
Essential regex syntax, character classes, anchors, lookarounds, and battle-tested validation patterns for all programming languages.
Character Classes & Matching
.
Matches any single character except newline (\n)
\d
Matches any digit (equivalent to [0-9])
\D
Matches any non-digit character (equivalent to [^0-9])
\w
Matches any alphanumeric word character or underscore [a-zA-Z0-9_]
\s
Matches any whitespace character (space, tab, newline)
Quantifiers & Repetition
*
Matches 0 or more occurrences (greedy)
+
Matches 1 or more occurrences (greedy)
?
Matches 0 or 1 occurrence (optional)
{n,m}
Matches between n and m occurrences
*?
Lazy/non-greedy quantifier (matches minimum required)
Anchors & Boundaries
^
Asserts position at the beginning of the string/line
$
Asserts position at the end of the string/line
\b
Word boundary (transition between word & non-word character)
Common Production Patterns
^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$
Standard RFC-compliant email address validation pattern
^https?:\/\/[\w\.-]+(?:\.[a-z]{2,})+(?:\/.*)?$
Standard HTTP/HTTPS web URL validator
^[a-z0-9]+(?:-[a-z0-9]+)*$
SEO URL slug validator (lowercase letters, numbers, and dashes)
^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{8,}$
Strong password validator (min 8 chars, 1 letter, 1 number)