Regex Cheatsheet
Complete regular expression reference with live tester.
Live Regex Tester
Anchors
| Token | Description | Example |
|---|---|---|
| ^ | Start of string/line | ^Hello matches "Hello world" |
| $ | End of string/line | world$ matches "Hello world" |
| \b | Word boundary | \bcat\b matches "cat" not "catch" |
| \B | Non-word boundary | \Bcat matches "catch" |
Character Classes
| Token | Description | Example |
|---|---|---|
| . | Any character except newline | a.c matches "abc" |
| \d | Digit [0-9] | \d+ matches "123" |
| \D | Non-digit | \D+ matches "abc" |
| \w | Word char [a-zA-Z0-9_] | \w+ matches "hello_1" |
| \W | Non-word character | \W matches spaces, punctuation |
| \s | Whitespace (space, tab, newline) | \s+ matches spaces |
| \S | Non-whitespace | \S+ matches words |
| [abc] | Character set (a, b, or c) | [aeiou] matches vowels |
| [^abc] | Negated set (not a, b, or c) | [^0-9] matches non-digits |
| [a-z] | Range (a to z) | [a-zA-Z] matches any letter |
Quantifiers
| Token | Description | Example |
|---|---|---|
| * | 0 or more (greedy) | ab* matches "a", "ab", "abbb" |
| + | 1 or more (greedy) | ab+ matches "ab", "abbb" |
| ? | 0 or 1 (optional) | colou?r matches "color" and "colour" |
| {n} | Exactly n times | \d{4} matches "2024" |
| {n,} | n or more times | \d{2,} matches "12", "123" |
| {n,m} | Between n and m times | \d{2,4} matches "12" to "1234" |
| *? | 0 or more (lazy) | a.*?b matches shortest string |
| +? | 1 or more (lazy) | a.+?b matches shortest string |
Groups & Lookarounds
| Token | Description | Example |
|---|---|---|
| (abc) | Capturing group | (foo)bar captures "foo" |
| (?:abc) | Non-capturing group | (?:foo)bar groups without capture |
| (?<name>abc) | Named capturing group | (?<year>\d{4}) |
| a|b | Alternation (a or b) | cat|dog matches "cat" or "dog" |
| (?=abc) | Positive lookahead | \d(?=px) matches digit before "px" |
| (?!abc) | Negative lookahead | \d(?!px) matches digit not before "px" |
| (?<=abc) | Positive lookbehind | (?<=\$)\d+ matches digits after $ |
| (?<!abc) | Negative lookbehind | (?<!\$)\d+ matches digits not after $ |
Common Patterns
| Pattern | Matches |
|---|---|
| ^\S+@\S+\.\S+$ | Basic email address |
| ^https?:\/\/.+ | HTTP/HTTPS URL |
| ^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$ | IPv4 address |
| ^\d{4}-\d{2}-\d{2}$ | ISO date (YYYY-MM-DD) |
| ^[a-zA-Z0-9_-]{3,16}$ | Username (3-16 chars) |
| ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$ | Strong password |
| ^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$ | Hex color code |
| ^\+?[1-9]\d{1,14}$ | International phone |
How to Use This Tool
- Open the Regex Cheatsheet and browse the entries listed in the main panel above.
- Use the search box or filters to jump directly to the value, symbol, or shortcut you need.
- Click any entry to copy it to your clipboard or to see a more detailed description.
Common Use Cases
- Quick lookups: Developers and writers consult the Regex Cheatsheet to jog memory on a specific code, symbol, or value without leaving the workflow.
- Teaching aids: Instructors share the page link with students learning the underlying notation or specification.
- Offline printout: Print the reference for a desk-side cheat sheet during interviews, certification prep, or fieldwork.
Frequently Asked Questions
Where does the data in the Regex Cheatsheet come from?
Entries are sourced from the official published specification (IANA, RFC, W3C, or vendor docs) and cross-checked against multiple references. Updates are applied when specs revise their assigned codes or descriptions.
Can I search by code or by name?
Yes. Use the search box to filter by either the code value or its descriptive name. Filtering happens live as you type, narrowing the list to entries that match in either column.
Is there a printable or exportable version?
Use your browser's print function to produce a paginated PDF or hard copy. Layout is optimized for letter and A4. For machine-readable export, copy the table content and paste into Excel or a CSV file.