Anchors & boundaries
| Token | Meaning |
^ $ | Start / end of string (or line with m) |
\b \B | Word / non-word boundary |
\A \z | String start / end (PCRE; not JS) |
Character classes
| Pattern | Matches |
[abc] | Any of a, b, c |
[^0-9] | Not a digit |
\d \D | Digit / non-digit |
\w \W | Word char / non-word |
\s \S | Whitespace / non-whitespace |
. | Any char except newline (unless s dotAll) |
Quantifiers
| Syntax | Greedy | Lazy |
| 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