🛠️ Developer10 min read·June 10, 2026
Regex for Beginners: 10 Patterns Every Developer Should Know
A regular expression (regex) is a pattern that matches text. Every developer eventually needs one — for validation, log parsing, or data extraction. Here are the 10 patterns worth memorising.
1. Email address
/^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,}$/Good enough for 99% of validation use cases. Not RFC-5322 compliant, but no production regex is.
2. URL (http/https)
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)/3. ISO date (YYYY-MM-DD)
/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/4. IPv4 address
/^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/5. Semantic version (x.y.z)
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/
6. Hex color code
/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/7. Slug (URL-safe string)
/^[a-z0-9]+(?:-[a-z0-9]+)*$/
8. JWT token structure
/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
9. Remove extra whitespace
str.replace(/\s+/g, ' ').trim()
10. Extract all numbers from a string
str.match(/-?\d+(\.\d+)?/g)
Need a pattern that isn't here? Describe it in plain English and let the AI Regex Generator build it for you.
Enjoyed this? Get notified when Pro launches.
