Regular Expressions (Regex) Cheat Sheet & Quick Reference
The definitive Regular Expression cheat sheet: character sets, greedy vs lazy quantifiers, positive/negative lookarounds, and RFC email/URL patterns with 1-click copy.
Character Classes (9 commands)
\d
Matches any single digit character from 0 through 9.
\D
Matches any single character that is not a numeric digit.
\w
Matches alphanumeric characters and underscore. Universal identifier pattern.
\W
Matches any symbol, punctuation, or whitespace character.
\s
Matches spaces, tabs, line breaks (\r, \n), and form feeds.
\S
Matches any visible, non-space character.
.
Matches any single character except newline (unless dotAll flag "s" is active).
[a-z0-9_]
Matches any single character enclosed within the brackets.
[^aeiou]
Matches any single character NOT present in the brackets.
Quantifiers & Multipliers (7 commands)
*
Matches preceding token 0 or more times as much as possible.
+
Matches preceding token at least 1 or more times.
?
Makes the preceding token optional (0 or 1 time).
{n}
Matches exactly n repetitions of the preceding token.
{2,5}
Matches between min and max occurrences inclusive.
*?
Stops matching at the earliest possible opportunity.
cat|dog
Matches either the expression on the left or the one on the right.
Anchors & Boundaries (4 commands)
^
Asserts position at the start of string (or line in multiline mode).
$
Asserts position at the end of string (or line in multiline mode).
\b
Asserts position at a word boundary (between \w and \W).
\B
Matches any position that is not a word boundary.
Groups & Lookarounds (6 commands)
(\w+)
Groups multiple tokens together and captures matching text for backreferences.
(?:abc)
Groups tokens for quantification without allocating backreference memory.
(?=pattern)
Asserts that the given pattern matches immediately after current position.
(?!pattern)
Asserts that the given pattern does NOT match immediately after current position.
(?<=pattern)
Asserts that the given pattern matches immediately before current position.
(?<!pattern)
Asserts that the given pattern does NOT match immediately before current position.
Production Patterns (7 commands)
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
Validates standard email format with modern gTLDs.
^(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$
Matches valid IPv4 addresses from 0.0.0.0 to 255.255.255.255.
^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$
Full web URL validator including query parameters and ports.
^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$
Matches standard ISO 8601 calendar date formats.
^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$
Validates 3 or 6 digit hex color codes with leading pound sign.
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$
Minimum 8 chars: at least 1 uppercase, 1 lowercase, 1 number, 1 special character.
^[a-z0-9]+(?:-[a-z0-9]+)*$
Validates lowercase, hyphen-separated SEO friendly URL slugs.