Characters
.Any char except \n (with s: any)
\dDigit [0-9]
\DNon-digit
\wWord char [a-zA-Z0-9_]
\WNon-word char
\sWhitespace (space, tab, newline…)
\SNon-whitespace
\t \nTab, newline
\0Null char
\xHHHex char (e.g. \x41 = A)
\uHHHHUnicode code point
Anchors
^Start of string (or line with m flag)
$End of string (or line with m flag)
\bWord boundary
\BNon-word boundary
\AStart of string (Python, Java, .NET)
\ZEnd of string (Python, Java, .NET)
Quantifiers
*0 or more (greedy)
+1 or more (greedy)
?0 or 1 (greedy)
{n}Exactly n times
{n,}n or more times
{n,m}Between n and m times
*?Lazy — 0 or more (shortest)
+?Lazy — 1 or more (shortest)
??Lazy — 0 or 1 (shortest)
*+Possessive — 0 or more (no backtrack, PCRE/Java)
++Possessive — 1 or more (no backtrack)
Character classes
[abc]Match a, b, or c
[^abc]Not a, b, or c
[a-z]Range: lowercase letter
[a-zA-Z]Range: any letter
[\d\w]Union of classes
.Outside class: any char
Groups
(abc)Capturing group
(?:abc)Non-capturing group
(?<n>abc)Named capturing group (use (?P<n>) in Python)
\1Backreference to group 1
\k<n>Named backreference
a|bAlternation: a or b
(?|…)Branch reset group (PCRE only)
Lookaround
(?=abc)Positive lookahead — followed by abc
(?!abc)Negative lookahead — not followed by abc
(?<=abc)Positive lookbehind — preceded by abc
(?<!abc)Negative lookbehind — not preceded by abc
⚠ Go/RE2Does not support lookaround or backreferences
⚠ C POSIXNo lookaround, no \d/\w/\s — use [0-9], [a-z], etc.
Flags
gGlobal — find all matches (JS/TS only as flag)
iCase-insensitive
mMultiline — ^ and $ match line boundaries
sDot-all — . matches newline too
xVerbose / extended — allow whitespace & comments (PCRE, Python, Java, .NET)
uUnicode — full Unicode matching (JS)