A comprehensive regular expression reference covering character classes, quantifiers, anchors, groups, lookaheads, common patterns, and flags. Bookmark this page for quick regex lookups while coding.
| Code / Syntax | Description |
|---|---|
. | Any character except newline |
\d | Digit (0-9) |
\D | Not a digit |
\w | Word character (a-z, A-Z, 0-9, _) |
\W | Not a word character |
\s | Whitespace (space, tab, newline) |
\S | Not whitespace |
[abc] | Any of a, b, or c |
[^abc] | Not a, b, or c |
[a-z] | Character range a to z |
[0-9a-fA-F] | Hexadecimal digit |
\t | Tab character |
| Code / Syntax | Description |
|---|---|
* | 0 or more |
+ | 1 or more |
? | 0 or 1 (optional) |
{3} | Exactly 3 times |
{3,} | 3 or more times |
{3,5} | Between 3 and 5 times |
*? | 0 or more (lazy / non-greedy) |
+? | 1 or more (lazy / non-greedy) |
?? | 0 or 1 (lazy / non-greedy) |
{3,5}? | Between 3 and 5 (lazy) |
| Code / Syntax | Description |
|---|---|
^ | Start of string (or line with m flag) |
$ | End of string (or line with m flag) |
\b | Word boundary |
\B | Not a word boundary |
^\s*$ | Match blank line |
\A | Start of string (never matches after newline) |
\Z | End of string (before final newline) |
\z | Absolute end of string |
| Code / Syntax | Description |
|---|---|
(abc) | Capturing group |
(?:abc) | Non-capturing group |
(?<name>abc) | Named capturing group |
\1 | Back-reference to group 1 |
(?=abc) | Positive lookahead |
(?!abc) | Negative lookahead |
(?<=abc) | Positive lookbehind |
(?<!abc) | Negative lookbehind |
(a|b) | Alternation — match a or b |
(?>abc) | Atomic group (no backtracking) |
| Code / Syntax | Description |
|---|---|
^[\w.-]+@[\w.-]+\.\w{2,}$ | Email address (basic) |
^https?://[\w.-]+(?:/\S*)?$ | URL (http/https) |
^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$ | IPv4 address |
^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$ | Hex color code |
^\d{4}-\d{2}-\d{2}$ | Date (YYYY-MM-DD) |
^\+?[1-9]\d{1,14}$ | Phone number (E.164) |
^-?\d+(\.\d+)?$ | Integer or decimal number |
^(?=.*[A-Z])(?=.*[a-z])(?=.*\d).{8,}$ | Strong password (8+ chars, upper, lower, digit) |
^\d{5}(-\d{4})?$ | US ZIP code |
<[^>]+> | HTML tag (basic) |
| Code / Syntax | Description |
|---|---|
g | Global — match all occurrences, not just first |
i | Case-insensitive matching |
m | Multiline — ^ and $ match line start/end |
s | Dotall — . matches newline characters |
u | Unicode — treat pattern as Unicode code points |
y | Sticky — match from lastIndex only |
d | Indices — generate match indices |
x | Extended — ignore whitespace and allow comments (some engines) |
Found this cheat sheet useful? Check out our other references and tools.