30 Practical Regex Patterns: Email, URL, Zip Code, Phone
A ready-to-copy regex pattern collection for real-world use, with edge case notes.
30 Practical Regex Patterns
Copy-paste ready regex patterns for real-world development.
Email Address
/^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$/
Practical pattern covering 99% of cases. Not RFC-complete by design.
URL (http/https)
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)/
US ZIP Code
/^\d{5}(-\d{4})?$/
IPv4 Address
/^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/
Date (YYYY-MM-DD)
/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/
Hex Color
/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/
Strong Password
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/
Takeaway
Regex is always a trade-off between strictness and practicality. These patterns prioritize real-world utility over RFC perfection.