Regex Templates
Common regular expression patterns ready to use
Email Address
Validates standard email format
/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/
Examples: test@example.com, user.name@domain.co.uk
URL
Matches HTTP/HTTPS URLs
/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$/
Examples: https://example.com, http://www.test.com/path
Phone Number (US)
Validates US phone number formats
/^1[3-9]\d{9}$/
Examples: 13812345678, 15987654321
Phone Number (International)
Validates international phone numbers
/^\+?[1-9]\d{1,14}$/
Examples: +14155552671, +8613812345678
Date (YYYY-MM-DD)
Matches ISO date format
/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/
Examples: 2025-03-01, 1999-12-31
Time (24-hour)
Matches 24-hour time format
/^([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$/
Examples: 14:30, 23:59:59
IPv4 Address
Validates IPv4 address format
/^(?:(?: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]?)$/
Examples: 192.168.1.1, 255.255.255.0
IPv6 Address
Validates IPv6 address format
/^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/
Examples: 2001:0db8:85a3:0000:0000:8a2e:0370:7334
Strong Password
At least 8 chars, uppercase, lowercase, number, special char
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/
Examples: Str0ng@Pass, MyP@ssw0rd
Username
Alphanumeric, 3-16 characters, underscores allowed
/^[a-zA-Z0-9_]{3,16}$/
Examples: john_doe, user123
URL Slug
Valid URL slug format
/^[a-z0-9]+(?:-[a-z0-9]+)*$/
Examples: my-blog-post, hello-world
Hex Color
Validates hex color codes
/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/
Examples: #FF5733, #fff, 00FF00
Credit Card
Validates major credit card numbers
/^(?: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})$/
Examples: 4111111111111111, 5500000000000004
HTML Tag
Matches HTML tags
/<([a-zA-Z][a-zA-Z0-9]*)[^>]*>(.*?)<\/\1>/
Examples: <div>content</div>, <p>text</p>
Chinese Characters
Matches Chinese characters only
/^[\u4e00-\u9fa5]+$/
Examples: 中文, 正则表达式