A comprehensive quick reference for regular expression syntax. Use this alongside our Regex Tester to build and test patterns.
| Character |
Description |
Example |
Matches |
. |
Any character except newline |
a.c |
"abc", "a1c", "a@c" |
\d |
Any digit |
\d{3} |
"123", "456" |
\D |
Any non-digit |
\D+ |
"abc", "!@#" |
\w |
Word character (a-z, A-Z, 0-9, _) |
\w+ |
"hello", "var_1" |
\W |
Non-word character |
\W |
" ", "@", "!" |
\s |
Whitespace (space, tab, newline) |
\s+ |
" ", "\t\n" |
\S |
Non-whitespace |
\S+ |
"hello" |
\b |
Word boundary |
\bcat\b |
"cat" in "the cat sat" |
\B |
Non-word boundary |
\Bcat\B |
"cat" in "concatenate" |
Character Classes
| Pattern |
Description |
Example |
Matches |
[abc] |
Any of a, b, or c |
[aeiou] |
Any vowel |
[^abc] |
Not a, b, or c |
[^0-9] |
Any non-digit |
[a-z] |
Range a to z |
[a-zA-Z] |
Any letter |
[0-9] |
Range 0 to 9 |
[0-9]+ |
"123", "7" |
[a-zA-Z0-9] |
Alphanumeric |
[a-zA-Z0-9_]+ |
"user_123" |
Quantifiers
| Quantifier |
Description |
Example |
Matches |
* |
0 or more |
ab*c |
"ac", "abc", "abbc" |
+ |
1 or more |
ab+c |
"abc", "abbc" (not "ac") |
? |
0 or 1 |
colou?r |
"color", "colour" |
{n} |
Exactly n |
\d{4} |
"2024" |
{n,} |
n or more |
\d{2,} |
"12", "123", "1234" |
{n,m} |
Between n and m |
\d{2,4} |
"12", "123", "1234" |
*? |
0 or more (lazy) |
<.*?> |
Shortest match |
+? |
1 or more (lazy) |
".+?" |
Shortest quoted string |
Anchors
| Anchor |
Description |
Example |
Matches |
^ |
Start of string/line |
^Hello |
"Hello" at start |
$ |
End of string/line |
end$ |
"end" at end |
\A |
Start of string only |
\AStart |
Start of entire string |
\Z |
End of string only |
End\Z |
End of entire string |
\b |
Word boundary |
\bword\b |
Whole word only |
Groups and Capturing
| Pattern |
Description |
Example |
(abc) |
Capturing group |
(ha)+ matches "haha" |
(?:abc) |
Non-capturing group |
(?:ha)+ matches but doesn't capture |
(?<name>abc) |
Named group |
(?<year>\d{4}) |
\1, \2 |
Backreference |
(\w+)\s+\1 matches "the the" |
(?=abc) |
Positive lookahead |
\d(?=px) matches "5" in "5px" |
(?!abc) |
Negative lookahead |
\d(?!px) matches "5" not followed by "px" |
(?<=abc) |
Positive lookbehind |
(?<=\$)\d+ matches "50" in "$50" |
(?<!abc) |
Negative lookbehind |
(?<!\$)\d+ matches "50" not after "$" |
Flags/Modifiers
| Flag |
Description |
i |
Case-insensitive matching |
g |
Global (find all matches) |
m |
Multiline (^ and $ match line boundaries) |
s |
Dotall (. matches newlines) |
x |
Verbose (ignore whitespace, allow comments) |
Common Patterns
Email Address
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
URL
https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)
Phone Number (US)
^(\+1)?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$
IP Address (IPv4)
^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$
Date (YYYY-MM-DD)
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$
Credit Card (basic)
^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13})$
Strong Password
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$
(Minimum 8 chars, 1 uppercase, 1 lowercase, 1 number, 1 special character)
HTML Tag
<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)
Hex Color
^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$
UUID
^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
Escape Sequences
These characters have special meaning and must be escaped with \ to match literally:
. * + ? ^ $ { } [ ] \ | ( )
Examples:
- Match a period:
\.
- Match a dollar sign:
\$
- Match a backslash:
\\
Language Differences
| Feature |
JavaScript |
Python |
C# |
| Named groups |
(?<name>) |
(?P<name>) |
(?<name>) |
| Unicode property |
\p{L} (ES2018+) |
\p{L} (regex module) |
\p{L} |
| Lookbehind |
✅ (ES2018+) |
✅ |
✅ |
| Atomic groups |
❌ |
❌ |
(?>) |
| Possessive quantifiers |
❌ |
❌ |
*+, ++ |