All Cheat SheetsRegex
Regular Expressions Cheat Sheet
Essential syntax, character classes, lookarounds, and common patterns
Anchors & Boundaries
Start of string / lineMatches the beginning of input
^End of string / lineMatches the end of input
$Word boundaryMatches a boundary between \w and \W
\bNon-word boundary
\BCharacter Classes
Any character (except newline)
.Digit [0-9]Non-digit: \D
\dWord character [a-zA-Z0-9_]Non-word: \W
\wWhitespace [ \t\r\n\f]Non-whitespace: \S
\sCustom character setNegated: [^a-z]
[a-z0-9_]Quantifiers
0 or more (greedy)
*1 or more (greedy)
+0 or 1 (optional)
?Exact count {n}e.g. \d{4} matches 4 digits
{4}Range {min, max}
{2,8}Lazy / Non-greedyMatches shortest possible match
*? or +?Lookarounds & Groups
Capturing group
(abc)Non-capturing group
(?:abc)Named group
(?<userName>[a-z]+)Positive lookaheadMatches 'foo' only if followed by 'bar'
foo(?=bar)Negative lookaheadMatches 'foo' only if NOT followed by 'bar'
foo(?!bar)Positive lookbehindMatches 'bar' only if preceded by 'foo'
(?<=foo)barEveryday Snippets
Email Address
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$IPv4 Address
^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$URL (HTTP/HTTPS)
^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_+.~#?&/=]*)$UUID (v4)
^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$