Regex Cheatsheet
Complete regular expression cheatsheet and reference guide. Quick lookup for regex syntax, character classes, quantifiers, anchors, groups, lookaheads, and common patterns.
Runs entirely in your browser — files never uploaded
| Pattern | Description | Example | Match | |
|---|---|---|---|---|
| . | Any character except newline | a.c | abc, aXc | |
| \d | Any digit [0-9] | \d{3} | 123, 456 | |
| \D | Any non-digit | \D+ | abc, !@# | |
| \w | Word character [a-zA-Z0-9_] | \w+ | hello, var_1 | |
| \W | Non-word character | \W | !, @, # | |
| \s | Whitespace (space, tab, newline) | a\sb | a b | |
| \S | Non-whitespace | \S+ | hello | |
| [abc] | Any of a, b, or c | [aeiou] | a, e, i | |
| [^abc] | Any character except a, b, or c | [^0-9] | a, Z, ! | |
| [a-z] | Any character in range a to z | [A-Z] | A, M, Z |
| Pattern | Description | Example | Match | |
|---|---|---|---|---|
| ^ | Start of string (or line with m flag) | ^Hello | Hello world | |
| $ | End of string (or line with m flag) | world$ | Hello world | |
| \b | Word boundary | \bcat\b | cat (not catch) | |
| \B | Non-word boundary | \Bcat | scat (not cat) |
| Pattern | Description | Example | Match | |
|---|---|---|---|---|
| * | 0 or more (greedy) | ab*c | ac, abc, abbc | |
| + | 1 or more (greedy) | ab+c | abc, abbc | |
| ? | 0 or 1 (optional) | colou?r | color, colour | |
| {n} | Exactly n times | \d{4} | 2024 | |
| {n,} | n or more times | \d{2,} | 12, 123, 1234 | |
| {n,m} | Between n and m times | \d{2,4} | 12, 123, 1234 | |
| *? | 0 or more (lazy) | <.*?> | <b> in <b>text</b> | |
| +? | 1 or more (lazy) | a+? | a in aaa |
| Pattern | Description | Example | Match | |
|---|---|---|---|---|
| (...) | Capturing group | (ab)+ | ab, abab | |
| (?:...) | Non-capturing group | (?:ab)+ | ab, abab | |
| (?=...) | Positive lookahead | \d(?=px) | 3 in 3px | |
| (?!...) | Negative lookahead | \d(?!px) | 3 in 3em | |
| (?<=...) | Positive lookbehind | (?<=\$)\d+ | 100 in $100 | |
| (?<!...) | Negative lookbehind | (?<!\$)\d+ | 100 in 100 | |
| \1 | Back-reference to group 1 | (\w+)\s\1 | the the | |
| $1 | Replacement reference to group 1 | s/(a)/[$1]/ | [a] |
| Pattern | Description | Example | Match | |
|---|---|---|---|---|
| g | Global — find all matches | /a/g | all a's in string | |
| i | Case-insensitive matching | /hello/i | Hello, HELLO | |
| m | Multiline — ^ and $ match line boundaries | /^a/m | a at line start | |
| s | Dotall — . matches newlines | /a.b/s | a\nb | |
| u | Unicode — full Unicode support | /\u{61}/u | a | |
| y | Sticky — match from lastIndex only | /a/y | a at lastIndex |
| Pattern | Description | Example | Match | |
|---|---|---|---|---|
| [\w.+-]+@[\w-]+\.[\w.]+ | Email address | user@example.com | user@example.com | |
| https?://[\w\-._~:/?#\[\]@!$&'()*+,;=%]+ | URL | https://example.com | https://example.com | |
| \+?[\d\s\-().]{7,15} | Phone number (international) | +1 (555) 123-4567 | +1 (555) 123-4567 | |
| \b\d{1,3}(\.\d{1,3}){3}\b | IPv4 address | 192.168.1.1 | 192.168.1.1 | |
| \d{4}-\d{2}-\d{2} | Date (YYYY-MM-DD) | 2024-01-15 | 2024-01-15 | |
| #([0-9a-fA-F]{3}){1,2}\b | Hex color code | #ff6600, #f60 | #ff6600 | |
| <([a-z]+)[^>]*>.*?</\1> | HTML tag (simple) | <div>text</div> | <div>text</div> | |
| \b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b | Credit card number | 1234 5678 9012 3456 | 1234 5678 9012 3456 |
How to use Regex Cheatsheet
- 1. Browse sections. Scroll through character classes, anchors, quantifiers, groups, flags, and common patterns.
- 2. Search for a pattern. Use the filter box at the top to quickly find the regex syntax you need.
- 3. Copy a pattern. Click the copy button next to any entry to copy the pattern to your clipboard.
FAQ
What regex flavor does this cover?
This cheatsheet covers JavaScript/ECMAScript regex syntax, which is widely compatible with other languages including Python, Java, and C#.
What is the difference between greedy and lazy quantifiers?
Greedy quantifiers (*, +) match as much as possible. Lazy quantifiers (*?, +?) match as little as possible. Use lazy when you want the shortest match.
What are lookaheads and lookbehinds?
Lookahead (?=...) and lookbehind (?<=...) assert that a pattern exists ahead or behind the current position without including it in the match. Negative versions (?!...) and (?<!...) assert absence.
Related tools
- Base64 EncoderEncode text or files to Base64 or decode Base64 back online for free. Instant conversion, no signup, runs in your browser.
- JSON FormatterFormat and validate JSON online for free. Beautify with indentation, validate syntax, or minify. Runs in your browser, no signup.
- CSV ↔ JSONConvert CSV to JSON or JSON to CSV online for free. Live preview as you type or upload a file. No signup, runs in browser.
- Timestamp ConverterConvert Unix timestamps to dates and dates to timestamps online for free. Supports seconds, milliseconds, ISO 8601. No signup.
- JWT DecoderDecode JWT tokens online for free. Inspect header, payload, and claims. Verify expiration and signature algorithm. No signup, runs in browser.
- Regex TesterTest regular expressions online for free with live match highlighting, capture groups, and flag toggles. Supports JavaScript regex. No signup.
Advertisement