Cheat sheetDev
Regex syntax
Every regex token you'll actually use, translated to one plain-English line — classes, quantifiers, anchors, groups and flags in one printable sheet.
Last updated
Character classes
| Token | Meaning |
|---|---|
| . | Any single character except a newline (the s flag adds newlines). |
| \d \D | A digit 0–9 / anything that isn't one. |
| \w \W | A word character (letter, digit, underscore) / anything else. |
| \s \S | Any whitespace (space, tab, newline) / anything that isn't. |
| [abc] | Exactly one character from the set: a, b or c. |
| [^abc] | One character that is NOT a, b or c — ^ negates only inside brackets. |
| [a-z0-9] | One character from either range; ranges and singles mix freely. |
Quantifiers
| Token | Meaning |
|---|---|
| * | The previous item, zero or more times. |
| + | The previous item, one or more times. |
| ? | The previous item, optional (zero or one). |
| {3} {2,5} {2,} | Exactly 3 / between 2 and 5 / at least 2 repetitions. |
| *? +? ?? | The lazy versions: match as LITTLE as possible instead of as much. |
Anchors & boundaries
| Token | Meaning |
|---|---|
| ^ $ | Start / end of the string (of each line, with the m flag). |
| \b | A word boundary — the zero-width seam between a word character and a non-word one. |
| \B | The opposite: a position that is NOT a word boundary. |
Groups & alternation
| Token | Meaning |
|---|---|
| (cat|dog) | Either alternative, captured as group 1. |
| (?:cat|dog) | Same choice, but not captured — cheaper and keeps numbering clean. |
| (?<name>…) | A named capture, read back as \k<name> or in match.groups.name. |
| \1 | Whatever group 1 actually matched, repeated here (a backreference). |
| (?=…) (?!…) | Lookahead: the next text must / must not match — without consuming it. |
| (?<=…) (?<!…) | Lookbehind: the preceding text must / must not match. |
Flags
| Token | Meaning |
|---|---|
| g | Global — find every match, not just the first. |
| i | Case-insensitive matching. |
| m | Multiline — ^ and $ also match at line breaks. |
| s | Dotall — . matches newlines too. |
| u | Unicode mode — treat the pattern as code points; needed for \p{…}. |
Worth remembering
- →To match a special character literally, escape it: \. \+ \( \[ — forgetting this on the dot is the most common regex bug in the wild.
- →Every token here is testable live in the Regex Tester — paste a pattern and your own text, nothing leaves the browser.