Character Classes
.Any character (except newline)
\dDigit [0-9]
\DNon-digit
\wWord char [a-zA-Z0-9_]
\WNon-word char
\sWhitespace
\SNon-whitespace
[abc]Any of a, b, or c
[^abc]Not a, b, or c
[a-z]Range: a to z
Quantifiers
*0 or more
+1 or more
?0 or 1
{n}Exactly n
{n,}n or more
{n,m}Between n and m
*?Lazy: 0 or more
+?Lazy: 1 or more
Anchors & Groups
^Start of string/line
$End of string/line
\bWord boundary
(abc)Capturing group
(?:abc)Non-capturing group
(?<name>abc)Named group
\1Backreference to group 1
a|bAlternation: a or b
Lookaround
(?=abc)Positive lookahead
(?!abc)Negative lookahead
(?<=abc)Positive lookbehind
(?<!abc)Negative lookbehind
Replace Tokens
$1, $2Capture group 1, 2
$&Entire match
$`Before match
$'After match