| Pattern | Matches | Example match |
|---|---|---|
\b[A-Za-z0-9._%+\-]+@[A-Za-z0-9.\-]+\.[A-Za-z]{2,}\b | Email address | user@example.com |
https?://[\w\-]+(\.[\w\-]+)+(/[\w\-./?%&=]*)? | URL (http/https) | https://tinker.bakemyweb.com |
\b\d{1,3}(\.\d{1,3}){3}\b | IPv4 address | 192.168.1.1 |
^\+?[1-9]\d{1,14}$ | E.164 phone number | +14155552671 |
\d{4}-\d{2}-\d{2} | ISO 8601 date | 2024-03-15 |
[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12} | UUID v4 | 550e8400-e29b-41d4-a716-446655440000 |
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$ | Hex colour code | #FF5733 |
^\d{5}(-\d{4})?$ | US ZIP code | 10001 or 10001-1234 |
| Token | Meaning |
|---|---|
. | Any character except newline (use s flag to include newlines) |
^ $ | Start / end of string (or line with m flag) |
\b | Word boundary — position between a word char and a non-word char |
\d \w \s | Digit [0-9] / word char [a-zA-Z0-9_] / whitespace |
\D \W \S | Negated versions of above |
* + ? | 0 or more / 1 or more / 0 or 1 (greedy) |
*? +? | Lazy (non-greedy) versions — match as few chars as possible |
{n} {n,m} | Exactly n / between n and m repetitions |
[abc] [^abc] | Character class / negated class |
(abc) | Capturing group — accessible as $1, $2… |
(?:abc) | Non-capturing group — groups without creating a backreference |
(?<name>abc) | Named capturing group — accessible as match.groups.name |
a|b | Alternation — match a or b |
| Flag | Effect |
|---|---|
g | Global — find all matches, not just the first |
i | Case-insensitive — A matches a |
m | Multiline — ^ and $ match start/end of each line |
s | DotAll — . matches newlines too |
u | Unicode — enables full Unicode matching and disallows invalid escapes |