Common Regex Patterns
Production-ready regular expressions for common validation tasks. Copy-paste these patterns into your code with confidence.
Contact
Email (Basic)
Validates most common email formats
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$user@example.comtest.name+tag@domain.co.ukEmail (RFC 5322)
Strict RFC 5322 compliant (complex)
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])complex+tag@sub.domain.comPhone Numbers
US Phone
US format with optional separators
^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$(123) 456-7890123-456-78901234567890International Phone
E.164 international format
^\+?[1-9]\d{1,14}$+14155552671+442071234567URLs & Web
URL (HTTP/HTTPS)
HTTP/HTTPS URLs with query params
^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$https://example.com/path?q=valuehttp://sub.domain.co.ukDomain Name
Valid domain names
^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$example.comsub.domain.co.ukURL Slug
URL-friendly slugs
^[a-z0-9]+(?:-[a-z0-9]+)*$hello-worldmy-blog-post-123Network
IPv4 Address
Valid IPv4 with range validation
^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$192.168.1.110.0.0.255IPv6 Address
Full IPv6 format
^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$2001:0db8:85a3:0000:0000:8a2e:0370:7334MAC Address
Network MAC address
^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$00:1A:2B:3C:4D:5E00-1A-2B-3C-4D-5EDate & Time
Date (YYYY-MM-DD)
ISO 8601 date format
^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01])$2024-12-252023-01-01Date (MM/DD/YYYY)
US date format
^(?:0[1-9]|1[0-2])\/(?:0[1-9]|[12][0-9]|3[01])\/\d{4}$12/25/202401/01/2023Time (24-hour)
24-hour time with optional seconds
^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$14:3023:59:59ISO 8601 DateTime
Full ISO 8601 datetime
^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?$2024-12-25T14:30:00Z2024-12-25T14:30:00+05:30Financial
Credit Card (All)
Visa, MasterCard, Amex, Discover
^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})$41111111111111115500000000000004Currency Amount
US currency format
^\$?\d{1,3}(?:,\d{3})*(?:\.\d{2})?$$1,234.561234.56$100Security
Strong Password
Min 8 chars, upper, lower, digit, special
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$SecureP@ss1MyP@ssw0rd!UUID v4
Version 4 UUID format
^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$550e8400-e29b-41d4-a716-446655440000MD5 Hash
32-character hex MD5
^[a-fA-F0-9]{32}$d41d8cd98f00b204e9800998ecf8427eSHA-256 Hash
64-character hex SHA-256
^[a-fA-F0-9]{64}$e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855Code & Identifiers
Hex Color
3 or 6 digit hex color
^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$#FFF#336699ff5733RGB Color
RGB color function
^rgb\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\)$rgb(255, 128, 0)rgb(0,0,0)HTML Tag
Basic HTML tag matching
<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)<div>content</div><br />Semantic Version
SemVer 2.0 compliant
^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$1.0.02.1.3-beta.11.2.3+build.456Text
Alphanumeric Only
Letters and numbers only
^[a-zA-Z0-9]+$Hello123ABCUsername
3-16 chars, letters, numbers, underscore
^[a-zA-Z0-9_]{3,16}$john_doeuser123No Special Characters
Alphanumeric with spaces
^[a-zA-Z0-9 ]+$Hello WorldTest 123Contains Only Letters
Latin letters only
^[a-zA-Z]+$HelloWorld๐ก Tips for Using These Patterns
- Test thoroughly: These patterns cover common cases but may need adjustment for edge cases in your specific application.
- Consider performance: Complex patterns with many alternations or lookarounds can be slow on large inputs.
- Escape in strings: When using in JavaScript/Python strings, you may need to double-escape backslashes (\\\\d โ \\d).
- Add flags as needed: Use /i for case-insensitive, /g for global matching.
External Resources
Test Patterns Instantly!
Copy a pattern and test it with your own data in real-time.
๐Open Regex Tester