All Cheat Sheets
Regex Cheat Sheet
Regular expression syntax reference — character classes, quantifiers, anchors, groups, and lookarounds.
Character Classes
.Any character except newlineDigit
\dDigit [0-9]Non-digit
\DNon-digitWord
\wWord char [a-zA-Z0-9_]Non-word
\WNon-word charSpace
\sWhitespaceNon-space
\SNon-whitespaceSet
[abc]Any of a, b, or cNegated set
[^abc]Not a, b, or cRange
[a-z]Range a to zQuantifiers
Star
*0 or morePlus
+1 or moreOptional
?0 or 1Exact
{n}Exactly nMin
{n,}n or moreRange
{n,m}Between n and mLazy star
*?0 or more (lazy)Lazy plus
+?1 or more (lazy)Anchors & Boundaries
Start
^Start of stringEnd
$End of stringBoundary
\bWord boundaryNon-boundary
\BNon-word boundaryGroups & References
Group
(abc)Capture groupNon-capture
(?:abc)Non-capture groupNamed
(?<name>abc)Named groupBack-ref
\1Back-referenceOr
a|bAlternation (OR)Lookaheads & Lookbehinds
Lookahead
(?=abc)Positive lookaheadNeg lookahead
(?!abc)Negative lookaheadLookbehind
(?<=abc)Positive lookbehindNeg lookbehind
(?<!abc)Negative lookbehindCommon Patterns
Email
[\w.-]+@[\w.-]+\.\w+URL
https?://[\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}