Regex Cheat Sheet
A categorized quick reference for regular expression syntax with a live pattern tester. Free online regex cheat sheet.
Quick Pattern Tester
Character Classes
| Pattern | Description | |
|---|---|---|
| . | Any character except newline | |
| \d | Any digit (0-9) | |
| \D | Any non-digit | |
| \w | Word character (letter, digit, underscore) | |
| \W | Non-word character | |
| \s | Whitespace (space, tab, newline) | |
| \S | Non-whitespace | |
| [abc] | Any of a, b, or c | |
| [^abc] | Any character except a, b, or c | |
| [a-z] | Any lowercase letter a through z |
Quantifiers
| Pattern | Description | |
|---|---|---|
| * | Zero or more of the preceding token | |
| + | One or more of the preceding token | |
| ? | Zero or one of the preceding token (optional) | |
| {n} | Exactly n occurrences | |
| {n,} | n or more occurrences | |
| {n,m} | Between n and m occurrences | |
| *? | Zero or more, non-greedy (lazy) | |
| +? | One or more, non-greedy (lazy) |
Anchors & Boundaries
| Pattern | Description | |
|---|---|---|
| ^ | Start of string (or line, with the m flag) | |
| $ | End of string (or line, with the m flag) | |
| \b | Word boundary | |
| \B | Not a word boundary |
Groups & Alternation
| Pattern | Description | |
|---|---|---|
| (abc) | Capturing group | |
| (?:abc) | Non-capturing group | |
| (?<name>abc) | Named capturing group | |
| a|b | Alternation — matches a or b | |
| (?=abc) | Positive lookahead | |
| (?!abc) | Negative lookahead | |
| (?<=abc) | Positive lookbehind | |
| (?<!abc) | Negative lookbehind |
Common Flags
| Pattern | Description | |
|---|---|---|
| g | Global — find all matches, not just the first | |
| i | Case-insensitive matching | |
| m | Multiline — ^ and $ match line boundaries | |
| s | Dot matches newline characters too |
Common Patterns
| Pattern | Description | |
|---|---|---|
| ^[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}$ | Email address | |
| ^https?:\/\/[\w.-]+(?:\.[a-zA-Z]{2,})+[\w\-._~:/?#[\]@!$&'()*+,;=]*$ | URL (http/https) | |
| ^\+?[0-9]{7,15}$ | Phone number (digits, optional leading +) | |
| ^\d{5}(-\d{4})?$ | US ZIP code (5 or ZIP+4) | |
| ^#(?:[0-9a-fA-F]{3}){1,2}$ | Hex color code | |
| ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$ | Password: 8+ chars, upper, lower, digit |
Free Regex Cheat Sheet — Common Patterns & Syntax
A categorized quick reference for regular expression syntax — character classes, quantifiers, anchors, groups, flags, and ready-to-use patterns for email, URL, phone, and more. Every pattern has a one-click copy button.
How to Use It
Browse the categorized tables below, or use the quick tester at the top to try a pattern against a sample string right away. Click the copy icon next to any pattern to grab it.
Example
Need an email-matching regex? Copy ^[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}$ straight from the Common Patterns table below.
Common Use Cases
- Looking up regex syntax you don't use often enough to memorize.
- Grabbing a ready-made pattern for email, URL, or password validation.
- Quickly testing whether a pattern matches a sample string before using it in code.
FAQs
Are these patterns guaranteed to cover every edge case?
No — patterns like the email and URL examples cover the vast majority of real-world cases but aren't exhaustive against every technically valid edge case in their respective specifications. For strict validation (like real email deliverability), pair regex checks with an actual verification step.
Does this tool support every regex flavor?
The reference and tester use JavaScript's regex engine (ECMAScript syntax). Most patterns here also work in PCRE-based languages like Python or PHP, but some advanced features may differ slightly.
Is my test data uploaded anywhere?
No — the quick tester runs entirely client-side in your browser. Nothing you type is sent to a server.
