.*
Developer Tools
Regex Quick Reference
Regular expressions metacharacters, quantifiers, anchors, groups, and lookahead/lookbehind syntax with examples.
📄 Free PDF Download
Print-friendly · 1-2 pages · No sign-up required
Metacharacters
| Pattern | Matches | Example |
|---|---|---|
. |
Any character (except newline) |
a.c → abc, aXc |
\d |
Any digit [0-9] |
\d+ → 42, 100 |
\D |
Non-digit |
\D+ → hello |
\w |
Word char [a-zA-Z0-9_] |
\w+ → hello_1 |
\W |
Non-word char |
\W → space, ! |
\s |
Whitespace (space, tab, newline) |
\s+ → spaces |
\S |
Non-whitespace |
\S+ → word |
Quantifiers
| Quantifier | Meaning | Example |
|---|---|---|
* |
0 or more (greedy) |
a* → '', a, aaa |
+ |
1 or more (greedy) |
a+ → a, aaa |
? |
0 or 1 (optional) |
colou?r → color, colour |
{n} |
Exactly n times |
\d{4} → 2026 |
{n,} |
n or more times |
\d{2,} → 12, 100 |
{n,m} |
Between n and m times |
\d{2,4} → 12, 123 |
*?, +?, ?? |
Lazy (non-greedy) |
<.+?> → <b> only |
Anchors & Boundaries
| Pattern | Matches |
|---|---|
^ |
Start of string (or line in multiline mode) |
$ |
End of string (or line in multiline mode) |
\b |
Word boundary |
\B |
Non-word boundary |
\A |
Start of entire string |
\Z |
End of entire string |
Groups & Alternation
| Pattern | Meaning | Example |
|---|---|---|
(abc) |
Capture group |
(foo)+ → foo, foofoo |
(?:abc) |
Non-capture group |
(?:foo)+ |
(?P<name>) |
Named capture group |
(?P<year>\d{4}) |
a|b |
Alternation (a or b) |
cat|dog |
[abc] |
Character class |
[aeiou] → vowels |
[^abc] |
Negated class |
[^0-9] → non-digit |
[a-z] |
Range |
[a-z] → lowercase |
Lookahead & Lookbehind
| Pattern | Type | Matches |
|---|---|---|
(?=...) |
Positive lookahead |
foo(?=bar) → foo in foobar |
(?!...) |
Negative lookahead |
foo(?!bar) → foo not before bar |
(?<=...) |
Positive lookbehind |
(?<=foo)bar → bar after foo |
(?<!...) |
Negative lookbehind |
(?<!foo)bar → bar not after foo |
Common Patterns
Email: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
URL: https?://[\w.-]+(?:/[\w./?=&#-]*)?
IP addr: \b(?:\d{1,3}\.){3}\d{1,3}\b
Date: \d{4}-\d{2}-\d{2}
Hex: #?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})
Phone: [+]?[(]?[0-9]{3}[)]?[-\s.]?[0-9]{3}[-\s.]?[0-9]{4,6}
Free Online Tools for Developer Tools
Keep This Reference Handy
Download the PDF and keep it on your desk or share with your team.
Download Regex Quick Reference PDF