All Cheat Sheets

Regex Cheat Sheet

Regular expression syntax reference — character classes, quantifiers, anchors, groups, and lookarounds.

Character Classes

.Any character except newline
Digit\dDigit [0-9]
Non-digit\DNon-digit
Word\wWord char [a-zA-Z0-9_]
Non-word\WNon-word char
Space\sWhitespace
Non-space\SNon-whitespace
Set[abc]Any of a, b, or c
Negated set[^abc]Not a, b, or c
Range[a-z]Range a to z

Quantifiers

Star*0 or more
Plus+1 or more
Optional?0 or 1
Exact{n}Exactly n
Min{n,}n or more
Range{n,m}Between n and m
Lazy star*?0 or more (lazy)
Lazy plus+?1 or more (lazy)

Anchors & Boundaries

Start^Start of string
End$End of string
Boundary\bWord boundary
Non-boundary\BNon-word boundary

Groups & References

Group(abc)Capture group
Non-capture(?:abc)Non-capture group
Named(?<name>abc)Named group
Back-ref\1Back-reference
Ora|bAlternation (OR)

Lookaheads & Lookbehinds

Lookahead(?=abc)Positive lookahead
Neg lookahead(?!abc)Negative lookahead
Lookbehind(?<=abc)Positive lookbehind
Neg lookbehind(?<!abc)Negative lookbehind

Common Patterns

Email[\w.-]+@[\w.-]+\.\w+
URLhttps?://[\w.-]+(?:/[\w./-]*)?
IPv4\d{1,3}(\.\d{1,3}){3}
Hex color#[0-9a-fA-F]{3,8}
Phone (US)\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}

Free tools for this

Keep the references coming

One email a week: new and trending developer tools, fresh comparisons, and what shipped. Unsubscribe in one click.