Loading…
Searchable reference for regular expression syntax with examples and one-click copy.
| Pattern | Description | |
|---|---|---|
^ | Start of string (or line in multiline mode) | |
$ | End of string (or line in multiline mode) | |
\b | Word boundary | transition between \w and \W | |
\B | Non-word boundary |
| Pattern | Description | |
|---|---|---|
\d | Any digit | equivalent to [0-9] | |
\w | Word character | [a-zA-Z0-9_] | |
\s | Whitespace | space, tab, newline, etc. | |
\D | Non-digit | [^0-9] | |
\W | Non-word character | [^a-zA-Z0-9_] | |
\S | Non-whitespace character | |
[abc] | Character set | matches a, b, or c | |
[^abc] | Negated set | matches anything except a, b, or c | |
[a-z] | Range | any lowercase letter a through z |
| Pattern | Description | |
|---|---|---|
* | Zero or more of the preceding element | |
+ | One or more of the preceding element | |
? | Zero or one | makes preceding element optional | |
{n} | Exactly n repetitions | |
{n,} | n or more repetitions | |
{n,m} | Between n and m repetitions (inclusive) | |
*? | Lazy (non-greedy) zero or more | matches as few as possible | |
+? | Lazy one or more | matches as few as possible |
| Pattern | Description | |
|---|---|---|
(abc) | Capturing group | captures the match for back-reference | |
(?:abc) | Non-capturing group | groups without capturing | |
(?=abc) | Positive lookahead | matches if followed by abc | |
(?!abc) | Negative lookahead | matches if NOT followed by abc | |
(?<=abc) | Positive lookbehind | matches if preceded by abc | |
(?<!abc) | Negative lookbehind | matches if NOT preceded by abc |
| Pattern | Description | |
|---|---|---|
^[\w.+-]+@[\w-]+\.[\w.]+$ | Email address (basic validation) | |
https?:\/\/[\w\-._~:/?#[\]@!$&'()*+,;=%]+ | URL (http or https) | |
^(\+1)?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$ | US phone number (various formats) | |
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$ | ISO date YYYY-MM-DD | |
^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$ | IPv4 address | |
^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$ | Hex color code | |
^\d{5}(-\d{4})?$ | US ZIP code (5 or 9 digit) | |
^4[0-9]{12}(?:[0-9]{3})?$ | Visa credit card number |