getdevutils.com/cheatsheets/regex-cheatsheet
| Char | Description | Example |
|---|---|---|
. | Any character | a.c → abc |
^ | Start of string | ^hello |
$ | End of string | world$ |
* | 0 or more | ab* → a, ab, abb |
+ | 1 or more | ab+ → ab, abb |
? | 0 or 1 | colou?r |
\ | Escape | \. → literal . |
| | Alternation | cat|dog |
| Class | Description | Equivalent |
|---|---|---|
\d | Digit | [0-9] |
\D | Non-digit | [^0-9] |
\w | Word char | [a-zA-Z0-9_] |
\W | Non-word | [^a-zA-Z0-9_] |
\s | Whitespace | [ \t\n\r] |
\S | Non-whitespace | [^ \t\n\r] |
\b | Word boundary | \bword\b |
| Quantifier | Description | Example |
|---|---|---|
{n} | Exactly n | \d{3} → 123 |
{n,} | n or more | \d{2,} → 12, 123 |
{n,m} | n to m | \d{2,4} → 12-1234 |
* | 0 or more | Same as {0,} |
+ | 1 or more | Same as {1,} |
? | 0 or 1 | Same as {0,1} |
*? | Lazy * | Minimal match |
+? | Lazy + | Minimal match |
| Syntax | Description |
|---|---|
(abc) | Capturing group |
(?:abc) | Non-capturing group |
(?=abc) | Positive lookahead |
(?!abc) | Negative lookahead |
(?<=abc) | Positive lookbehind |
(? | Negative lookbehind |
\1 | Backreference to group 1 |
(?<name>) | Named group |
| Expression | Description | Example Match |
|---|---|---|
[abc] | Any of a, b, or c | a, b, c |
[^abc] | Not a, b, or c | d, e, 1 |
[a-z] | Lowercase letters | a, m, z |
[A-Z] | Uppercase letters | A, M, Z |
[0-9] | Digits | 0, 5, 9 |
[a-zA-Z] | All letters | a, Z |
[a-zA-Z0-9] | Alphanumeric | a, Z, 5 |
^[\w.+-]+@[\w.-]+\.[a-zA-Z]{2,}$
user@example.com
https?://[\w.-]+\.[a-z]{2,}
https://example.com
\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}
(555) 123-4567
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}
192.168.1.1
\d{4}-\d{2}-\d{2}
2025-01-27
([01]?\d|2[0-3]):[0-5]\d
23:59
#?[A-Fa-f0-9]{6}
#FF5733
[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}
UUID v4 format
\d{5}(-\d{4})?
12345, 12345-6789
^[a-zA-Z0-9_]{3,16}$
3-16 chars, alphanumeric
(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}
Upper, lower, digit, 8+
\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}
1234-5678-9012-3456
| Flag | Description |
|---|---|
i | Case insensitive |
g | Global (find all) |
m | Multiline mode |
s | Dot matches newline |
u | Unicode support |
x | Extended (ignore whitespace) |
^\s+ | Leading whitespace |
\s+$ | Trailing whitespace |
\s{2,} | Multiple spaces |
<[^>]+> | HTML tags |
#[a-zA-Z0-9_]+ | Hashtags |
@[a-zA-Z0-9_]+ | @mentions |