| Pattern | Matches / Meaning | Example |
|---|---|---|
. | Any character except newline | he.llo |
\d | Any digit (0-9) | \d{3} |
\D | Any non-digit | \D{3} |
\w | Any word character (a-z, A-Z, 0-9, _) | \w{3} |
\W | Any non-word character | \W{3} |
\s | Any whitespace character | \s{3} |
\S | Any non-whitespace character | \S{3} |
[abc] | Any character in the set | [abc]{3} |
[^abc] | Any character not in the set | [^abc]{3} |
[a-z] | Any lowercase letter | [a-z]{3} |
[A-Z] | Any uppercase letter | [A-Z]{3} |
[0-9] | Any digit | [0-9]{3} |
[a-zA-Z] | Any letter | [a-zA-Z]{3} |
[^a-zA-Z] | Any non-letter | [^a-zA-Z]{3} |
[0-9a-fA-F] | Any hexadecimal digit | [0-9a-fA-F]{3} |
| Pattern | Matches / Meaning | Example |
|---|---|---|
^ | Start of string | ^hello |
$ | End of string | hello$ |
\b | Word boundary | \bhello\b |
\B | Non-word boundary | \Bhello\B |
\A | Start of string (multiline) | \Ahello |
\Z | End of string (multiline) | hello\Z |
\z | End of string (strict) | hello\z |
| Pattern | Matches / Meaning | Example |
|---|---|---|
* | Zero or more of the preceding element | he*llo |
+ | One or more of the preceding element | he+llo |
? | Zero or one of the preceding element | he?llo |
{n} | Exactly n occurrences of the preceding element | he{2}llo |
{n,} | n or more occurrences of the preceding element | he{2,}llo |
{n,m} | Between n and m occurrences of the preceding element | he{2,4}llo |
*? | Zero or more of the preceding element (lazy) | he*?llo |
+? | One or more of the preceding element (lazy) | he+?llo |
?? | Zero or one of the preceding element (lazy) | he??llo |
{n,m}? | Between n and m occurrences (lazy) | he{2,4}?llo |
| Pattern | Matches / Meaning | Example |
|---|---|---|
(group) | Grouping | (he){2}llo |
(?:non-capturing) | Non-capturing group | (?:he){2}llo |
\1 | Backreference to the first group | (he)\1llo |
\2 | Backreference to the second group | (he)(wo)\2llo |
(? | Named group | (? |
\k<name> | Backreference by name | (? |
(?:...) | Non-capturing group | (?:he){2}llo |
(?=...) | Positive lookahead | he(?=llo) |
(?!...) | Negative lookahead | he(?!llo) |
(?<=...) | Positive lookbehind | (?<=he)llo |
(?<!...) | Negative lookbehind | (? |
| Pattern | Matches / Meaning | Example |
|---|---|---|
(?=) | Positive lookahead | he(?=llo) |
(?!) | Negative lookahead | he(?!llo) |
(?<=) | Positive lookbehind | (?<=he)llo |
(? | Negative lookbehind | (? |
(?=(?=...)) | Nested lookahead | he(?=(?=llo)) |
(?=(?!...)) | Nested negative lookahead | he(?=(?!llo)) |
(?<=...)(?=...) | Combined lookbehind and lookahead | (?<=he)(?=llo) |
| Pattern | Matches / Meaning | Example |
|---|---|---|
g | Global search | he/g |
i | Case-insensitive search | he/i |
m | Multiline search | he/m |
s | Dot matches newline | he/s |
x | Ignore whitespace and comments | he/x |
u | Unicode mode | he/u |
y | Sticky search | he/y |
gi | Global and case-insensitive | he/gi |
gm | Global and multiline | he/gm |
| Pattern | Matches / Meaning | Example |
|---|---|---|
\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b | Email address | example@example.com |
https?://[^\s/$.?#].[^\s]* | URL | http://example.com |
\b(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b | IPv4 address | 192.168.1.1 |
#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}) | Hex color | #ff0000 |
\d{4}-\d{2}-\d{2} | ISO date | 2023-10-05 |
\d{2}\/\d{2}\/\d{4} | MM/DD/YYYY date | 10/05/2023 |
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} | IPv4 address (simplified) | 192.168.1.1 |
^0x[0-9a-fA-F]+$ | Hexadecimal number | 0xFF |
^\d{3}-\d{2}-\d{4}$ | US SSN | 123-45-6789 |
^\+?[1-9]\d{0,15}$ | Phone number | +1234567890 |
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ | Basic email | user@domain.com |
^([0-9]{4})-([0-9]{2})-([0-9]{2})$ | ISO date with groups | 2023-10-05 |
^([0-9]{1,3}\.){3}[0-9]{1,3}$ | IPv4 with groups | 192.168.1.1 |
^#([A-Fa-f0-9]{3}|[A-Fa-f0-9]{6})$ | Hex color with groups | #ff0000 |
^https?:\/\/[^\s\/$.?#].[^\s]*$ | URL with groups | http://example.com |