Anchors & boundaries

TokenMeaning
^ $Start / end of string (or line with m)
\b \BWord / non-word boundary
\A \zString start / end (PCRE; not JS)

Character classes

PatternMatches
[abc]Any of a, b, c
[^0-9]Not a digit
\d \DDigit / non-digit
\w \WWord char / non-word
\s \SWhitespace / non-whitespace
.Any char except newline (unless s dotAll)

Quantifiers

SyntaxGreedyLazy
0 or more**?
1 or more++?
0 or 1?
Exactly n{n}
n to m{n,m}{n,m}?

Groups & lookahead

(abc)        # capturing group
(?:abc)      # non-capturing
(?<name>...)  # named capture (JS)
(?=...)      # positive lookahead
(?!...)      # negative lookahead

JavaScript flags

g global · i ignore case · m multiline · s dotAll · u unicode · y sticky