Regex Patterns You'll Actually Use
Regular expressions are powerful, cryptic, and unavoidable. This isn't a regex tutorial — it's a reference of patterns you'll copy-paste repeatedly in real projects.
Email Validation
/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/This is the "good enough" email regex. It's not RFC 5322 compliant (nothing practical is), but it catches 99% of valid emails and rejects obvious garbage. For production, send a verification email instead of trying to validate with regex.
URL
/^https?:\/\/[^\s]+$/Simple and effective. For stricter validation:
/^https?:\/\/[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z]{2,})+(\/[^\s]*)?$/Strong Password
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*]).{8,}$/Requires: lowercase, uppercase, digit, symbol, 8+ chars. Uses lookaheads (?=) to check each requirement without consuming characters.
Phone Numbers
# International
/^\+?[1-9]\d{1,14}$/
# Brazilian
/^\(?\d{2}\)?\s?\d{4,5}-?\d{4}$/
# US
/^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/IP Addresses
# IPv4
/^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/
# Simple (doesn't validate ranges)
/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/Date Formats
# YYYY-MM-DD
/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/
# DD/MM/YYYY
/^(?:0[1-9]|[12]\d|3[01])\/(?:0[1-9]|1[0-2])\/\d{4}$/Extracting Data
# Extract domain from URL
url.match(/https?:\/\/([^/]+)/)?.[1]
# Extract all hashtags
text.match(/#\w+/g)
# Extract numbers
text.match(/-?\d+\.?\d*/g)
# Extract content between quotes
text.match(/"([^"]+)"/g)Regex Tips
- Non-greedy: Use
.*?instead of.*to match the shortest possible string - Named groups:
(?<year>\d{4})-(?<month>\d{2})for readable matches - Negative lookahead:
foo(?!bar)matches "foo" not followed by "bar" - Word boundary:
\bword\bmatches whole words only
Test your patterns: Regex Cheatsheet — searchable reference with copy-to-clipboard. Or use our Regex Tester for live testing.