Cheat Sheets
Regex Cheatsheet
Search and copy practical regex snippets, grouped by category with quick examples.
Search Regex Patterns
Character Classes
| Title | Description | Pattern | Example | Matched |
|---|---|---|---|---|
| Any digit | Matches a single digit 0-9. | \d | Order 42 | 4 |
| Any non-digit | Matches non-digit runs. | \D+ | ABC! 123 | ABC! |
| Word character run | Matches letters, digits, underscore. | \w+ | user_name1 and _ok | user_name1 |
| Whitespace | Matches spaces, tabs, newlines. | \s+ | line one\nline two |
Anchors
| Title | Description | Pattern | Example | Matched |
|---|---|---|---|---|
| Start of line | Matches Hello at the start. | ^Hello | Hello world | Hello |
| End of line | Matches world at the end. | world$ | Hello world | world |
Quantifiers
| Title | Description | Pattern | Example | Matched |
|---|---|---|---|---|
| Zero or more | o appears zero or more times. | go*gle | ggle google gooogle | ggle, google, gooogle |
| One or more | o appears one or more times. | go+gle | ggle google gooogle | google, gooogle |
| Optional | u is optional. | colou?r | color colour | color, colour |
| Exact range | Matches numbers with length 2-4. | \d{2,4} | 7 42 512 10001 | 42, 512, 1000 |
Groups
| Title | Description | Pattern | Example | Matched |
|---|---|---|---|---|
| Capturing group | Captures repeated abc. | (abc)+ | abcabc xyz | abcabc |
| Non-capturing group | Groups protocol variants without capturing. | (?:https?)://\S+ | http://a.com https://b.dev | http://a.com, https://b.dev |
| Named group | Captures named parts. | (?<year>\d{4})-(?<month>\d{2}) | 2026-05 release | 2026-05 |
Lookarounds
| Title | Description | Pattern | Example | Matched |
|---|---|---|---|---|
| Positive lookahead | Word before @ sign. | \w+(?=@) | hello@example.com | hello |
| Negative lookahead | foo not followed by bar. | foo(?!bar) | foo foobar fooz | foo, foo |
| Positive lookbehind | Numbers after dollar sign. | (?<=\$)\d+ | $25 and $300 | 25, 300 |
| Negative lookbehind | Numbers not preceded by -. | (?<!-)\d+ | -10 20 -3 7 | 0, 20, 7 |
Flags
| Title | Description | Pattern | Example | Matched |
|---|---|---|---|---|
| Global flag | Finds all lowercase cat matches. | /cat/g | cat CAT cat | cat, cat |
| Ignore case flag | Matches cat in any case (first match). | /cat/i | CAT cat cAt | CAT |
| Multiline flag | ^ applies per line. | /^error/m | info\nerror\nwarn | error |
| Dotall flag | Dot can match newlines. | /a.b/s | a\nb | a\nb |
| Unicode flag | Unicode letter matching. | /\p{L}+/u | naïve café | naïve, café |
| Sticky flag | Matches from current index only. | /\d+/y | 123-45 | 123 |
Escape Sequences
| Title | Description | Pattern | Example | Matched |
|---|---|---|---|---|
| Newline | Matches a line break character. | \n | line1\nline2 | \n |
| Tab | Matches a tab character. | \t | A\tB | \t |
| Word boundary | Matches cat as a full word. | \bcat\b | cat scatter catalog | cat |
| Literal dot | Matches an actual . character. | \. | v1.2.3 | ., . |
| Literal backslash | Matches \ in text. | \\ | C:\\\\Tools\\\\Regex | \\, \\, \\, \\ |
Common Patterns
| Title | Description | Pattern | Example | Matched |
|---|---|---|---|---|
| Basic email matcher. | \b[\w.%+-]+@[\w.-]+\.[A-Za-z]{2,}\b | hello@example.com | hello@example.com | |
| URL (http/https) | Matches web URLs. | https?:\/\/[^\s]+ | https://google.com | https://google.com |
| Hex color | Matches 3 or 6-char hex colors. | #(?:[0-9a-fA-F]{3}){1,2}\b | #0ea5e9 | #0ea5e9 |
| IPv4 | Matches IPv4 addresses. | \b(?:25[0-5]|2[0-4]\d|1?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|1?\d?\d)){3}\b | 192.168.1.10 | 192.168.1.10 |
| Date (YYYY-MM-DD) | Matches ISO-like calendar dates. | \b\d{4}-\d{2}-\d{2}\b | 2026-05-28 | 2026-05-28 |