Regex Practical Guide
Regex clicks once you stop memorizing patterns and start thinking in pieces.
Core syntax
| Pattern | Meaning |
|---|---|
. | any character except newline |
* | 0 or more |
+ | 1 or more |
? | 0 or 1 (optional) |
^ | start of string |
$ | end of string |
[abc] | character class |
[^abc] | negated class |
\d | digit [0-9] |
\w | word char [a-zA-Z0-9_] |
\s | whitespace |
Useful patterns
# Email (basic)
[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}
# URL
https?://[\w./-]+
# IPv4
\b\d{1,3}(\.\d{1,3}){3}\b
# Date YYYY-MM-DD
\d{4}-\d{2}-\d{2}
# Hex color
#[0-9a-fA-F]{6}Python example
import re
text = "Contact: hello@example.com or support@test.org"
emails = re.findall(r'[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}', text)
print(emails) # ['hello@example.com', 'support@test.org']Tip
Use regex101.com to test interactively. Always test on real data before deploying.

