Regex Cheat Sheet
Complete regular expression reference — anchors, quantifiers, groups, lookaheads, and flags.
Anchors
| Pattern | Description |
|---|---|
| ^ | Start of string (or line in multiline mode) |
| $ | End of string (or line in multiline mode) |
| \b | Word boundary |
| \B | Non-word boundary |
| \A | Start of string (no multiline) |
| \Z | End of string (no multiline) |
Character Classes
| Pattern | Description |
|---|---|
| . | Any character except newline |
| \d | Digit [0–9] |
| \D | Non-digit |
| \w | Word character [A-Za-z0-9_] |
| \W | Non-word character |
| \s | Whitespace (space, tab, newline) |
| \S | Non-whitespace |
| [abc] | Character set — any of a, b, or c |
| [^abc] | Negated character set |
| [a-z] | Character range |
| [a-zA-Z] | Case-insensitive range |
Quantifiers
| Pattern | Description |
|---|---|
| * | Zero or more (greedy) |
| + | One or more (greedy) |
| ? | Zero or one (optional) |
| {n} | Exactly n times |
| {n,} | n or more times |
| {n,m} | Between n and m times |
| *? | Zero or more (lazy) |
| +? | One or more (lazy) |
| ?? | Zero or one (lazy) |
Groups & Alternation
| Pattern | Description |
|---|---|
| (abc) | Capture group — captures match |
| (?:abc) | Non-capturing group |
| (?P<name>abc) | Named capture group |
| a|b | Alternation — a or b |
| \1 | Backreference to group 1 |
Lookahead & Lookbehind
| Pattern | Description |
|---|---|
| (?=abc) | Positive lookahead — followed by |
| (?!abc) | Negative lookahead — not followed by |
| (?<=abc) | Positive lookbehind — preceded by |
| (?<!abc) | Negative lookbehind — not preceded by |
Flags
| Pattern | Description |
|---|---|
| g | Global — find all matches (not just first) |
| i | Case-insensitive match |
| m | Multiline — ^ and $ match line boundaries |
| s | Dotall — . matches newline too |
| u | Unicode — enables Unicode escapes |
| y | Sticky — match at lastIndex only |
| d | Indices — report match indices |
Special & Escape
| Pattern | Description |
|---|---|
| \n | Newline |
| \t | Tab |
| \r | Carriage return |
| \uXXXX | Unicode code point |
| \xHH | Hex code point |
| \0 | Null character |
| \\ | Literal backslash |
Using this regex cheat sheet
Regular expressions are patterns used to match character combinations in strings. Most engines support PCRE-style syntax: anchors, character classes, quantifiers, groups, and lookaheads. JavaScript adds the g, i, m,s, u, and y flags via the RegExp object.
To test a regex against sample text, use the Regex Tester. To visualize how a pattern matches, try the Regex Visualizer. To escape special characters, see Regex Escape Tool.
Private & free — this tool runs entirely in your browser.
Recommended: IndieKit — Ship your Next.js startup in days.affiliate
Related Developer Utilities tools
RegExp Tester
Test regular expressions and inspect matches locally.
Regex Visualizer
Visual regex pattern diagram with live match highlighting and capture group annotations.
Subnet Calculator
Compute CIDR subnets, usable hosts, and network ranges.
Cron Parser
Translate cron syntax into plain English.
URL Parser
Break a URL into protocol, host, path, and query parts.
HTML Previewer
Paste HTML and see it rendered live in a safe, sandboxed preview.
HTTP Status Code Reference
Search and look up every HTTP status code and its meaning.
MIME Type Lookup
Find the MIME type for a file extension, or the extensions for a MIME type.