Online regex cheat sheet
Quick online reference for regular expression syntax — character classes, quantifiers, anchors, groups, and copy-paste patterns with examples. Click any row to open the regex tester with that pattern pre-loaded.
Character classes
| Pattern | Meaning | Example |
|---|---|---|
. | Any character except newline | a.b → acb |
\d | Digit 0–9 | \d\d → 42 |
\D | Non-digit | \D+ → abc |
\w | Word character [A-Za-z0-9_] | \w+ → hello_1 |
\W | Non-word character | \W → ! |
\s | Whitespace (space, tab, newline) | \s+ → |
\S | Non-whitespace | \S+ → word |
[abc] | Any of a, b, or c | [aeiou] → e |
[^abc] | Any character except a, b, or c | [^0-9] → x |
[a-z] | Lowercase letter | [a-z]+ → hello |
[A-Z] | Uppercase letter | [A-Z]+ → HELLO |
[0-9] | Digit | [0-9]{3} → 123 |
Anchors
Quantifiers
Groups & alternation
| Pattern | Meaning | Example |
|---|---|---|
(abc) | Capturing group | (\w+)@(\w+) |
(?:abc) | Non-capturing group | (?:https?)://\w+ |
(?<name>abc) | Named capturing group | (?<user>\w+) |
a|b | Alternation — a or b | cat|dog |
Lookahead & lookbehind
Common patterns
| Pattern | Meaning | Example |
|---|---|---|
\b\w+@\w+\.\w+\b | Email address (simple) | user@example.com |
https?://[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#\[\]@!$&'()*+,;=.]* | URL (http/https) | https://toolwork.dev |
#[0-9a-fA-F]{3,8}\b | Hex color code | #22d3ee |
\b\d{1,3}(?:\.\d{1,3}){3}\b | IPv4 address | 192.168.1.1 |
\b\d{4}-\d{2}-\d{2}\b | ISO date (YYYY-MM-DD) | 2026-06-10 |
\b[A-Z]{2,3}-\d{4,}\b | Ticket / reference ID | TW-12345 |
(?<quote>['"])(?<value>(?:\\.|(?!\k<quote>).)*?)\k<quote> | Quoted string (single or double) | "hello world" |
\/\*[\s\S]*?\*\/|\/\/.*$ | Block or line comment | // comment |