Common regex patterns
Tested patterns for the things developers validate every week. Each page shows what passes, what fails, the caveats, and code for JavaScript and Python.
- Email address
^[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-… - Phone number
^(?:\+?1[-. ]?)?\(?([2-9][0-9]{2})\)?[-. ]?([2-9][0-9]{2})[-… - URL
^https?:\/\/(?:[A-Za-z0-9-]+\.)+[A-Za-z]{2,}(?::\d{2,5})?(?:… - IPv4 address
^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-… - Date (YYYY-MM-DD)
^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$ - Time (24-hour)
^([01]\d|2[0-3]):([0-5]\d)(?::([0-5]\d))?$ - UUID
^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-… - Hex colour
^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$ - Strong password
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{12,}$ - ZIP / postal code
^\d{5}(?:-\d{4})?$ - URL slug
^[a-z0-9]+(?:-[a-z0-9]+)*$ - HTML tag
<\/?([a-zA-Z][a-zA-Z0-9-]*)\b[^>]*> - Credit card number
^(?:4\d{12}(?:\d{3})?|5[1-5]\d{14}|2(?:2[2-9][1-9]|2[3-9]\d|… - Extra whitespace
[ \t]{2,}
Can't find yours? Describe it on the AI regex generator and test the result in the regex tester.