Regex library

78 validated patterns. Every one is proven with real sample tests.

Email address

^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

Matches a standard email address such as name@example.com.

URL (http/https)

^https?://[^\s/$.?#].[^\s]*$

Matches an http or https web URL.

US phone number

^(\+1[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$

Matches a US phone number, optionally with +1 and separators.

China mobile phone number

^1[3-9]\d{9}$

Matches a mainland China 11-digit mobile number.

IPv4 address

^((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$

Matches a valid IPv4 address (0-255 per octet).

ISO date (YYYY-MM-DD)

^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$

Matches an ISO 8601 calendar date like 2026-07-13.

24-hour time (HH:MM)

^([01]\d|2[0-3]):[0-5]\d$

Matches 24-hour clock time such as 09:30 or 23:59.

Hex color code

^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$

Matches a #RGB or #RRGGBB hex color code.

UUID (v4-ish)

^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$

Matches an RFC-4122 UUID string.

URL slug

^[a-z0-9]+(?:-[a-z0-9]+)*$

Matches a lowercase URL slug like my-blog-post.

Username (3-16, alnum/underscore)

^[a-zA-Z0-9_]{3,16}$

Matches a username of 3-16 letters, digits or underscores.

Strong password

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\w\s]).{8,}$

Requires 8+ chars with lower, upper, digit and symbol.

Integer (signed)

^[+-]?\d+$

Matches an optionally signed whole number.

Decimal number

^[+-]?(\d+\.?\d*|\.\d+)$

Matches an optionally signed decimal number.

Hashtag

^#[A-Za-z0-9_]+$

Matches a social media hashtag like #OpenAI.

US ZIP code

^\d{5}(-\d{4})?$

Matches a US ZIP or ZIP+4 postal code.

IPv6 address (full form)

^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$

Matches a fully written (uncompressed) IPv6 address.

MAC address

^([0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}$

Matches a MAC hardware address with : or - separators.

Credit card number

^\d{13,16}$

Matches a 13-16 digit credit card number (format only).

12-hour time (with AM/PM)

^(0?[1-9]|1[0-2]):[0-5]\d\s?([AaPp][Mm])$

Matches a 12-hour clock time such as 09:30 AM or 12:00pm.

US date (MM/DD/YYYY)

^(0[1-9]|1[0-2])/(0[1-9]|[12]\d|3[01])/\d{4}$

Matches a US-format date like 07/13/2026.

Semantic version

^\d+\.\d+\.\d+$

Matches a semantic version number like 1.2.3.

Domain name

^([a-zA-Z0-9](-?[a-zA-Z0-9])*\.)+[a-zA-Z]{2,}$

Matches a bare domain name like example.com.

US currency amount

^\$\d{1,3}(,\d{3})*(\.\d{2})?$

Matches a US dollar amount like $1,000.00.

Decimal with 2 places

^\d+\.\d{2}$

Matches a number with exactly two decimal places.

No whitespace

^\S+$

Matches a string containing no whitespace characters.

Alphanumeric only

^[a-zA-Z0-9]+$

Matches letters and digits only (no symbols or spaces).

HTML opening tag

^<[a-zA-Z][a-zA-Z0-9]*(\s[^>]*)?>$

Matches an HTML opening tag such as <div> or <a href='x'>.

Positive integer

^[1-9]\d*$

Matches a positive whole number with no leading zero.

Hexadecimal number

^0[xX][0-9a-fA-F]+$

Matches a hex literal like 0x1A3F.

1 digit number

^\d{1}$

Matches a number with exactly 1 digit(s).

2 digit number

^\d{2}$

Matches a number with exactly 2 digit(s).

3 digit number

^\d{3}$

Matches a number with exactly 3 digit(s).

4 digit number

^\d{4}$

Matches a number with exactly 4 digit(s).

5 digit number

^\d{5}$

Matches a number with exactly 5 digit(s).

6 digit number

^\d{6}$

Matches a number with exactly 6 digit(s).

7 digit number

^\d{7}$

Matches a number with exactly 7 digit(s).

8 digit number

^\d{8}$

Matches a number with exactly 8 digit(s).

9 digit number

^\d{9}$

Matches a number with exactly 9 digit(s).

10 digit number

^\d{10}$

Matches a number with exactly 10 digit(s).

11 digit number

^\d{11}$

Matches a number with exactly 11 digit(s).

12 digit number

^\d{12}$

Matches a number with exactly 12 digit(s).

13 digit number

^\d{13}$

Matches a number with exactly 13 digit(s).

14 digit number

^\d{14}$

Matches a number with exactly 14 digit(s).

15 digit number

^\d{15}$

Matches a number with exactly 15 digit(s).

16 digit number

^\d{16}$

Matches a number with exactly 16 digit(s).

at least 2 digits

^\d{2,}$

Matches a number with 2 or more digits.

at least 3 digits

^\d{3,}$

Matches a number with 3 or more digits.

at least 4 digits

^\d{4,}$

Matches a number with 4 or more digits.

at least 5 digits

^\d{5,}$

Matches a number with 5 or more digits.

at least 6 digits

^\d{6,}$

Matches a number with 6 or more digits.

at least 8 digits

^\d{8,}$

Matches a number with 8 or more digits.

at least 10 digits

^\d{10,}$

Matches a number with 10 or more digits.

string of exactly 1 characters

^.{1}$

Matches any string that is exactly 1 character(s) long.

string of exactly 2 characters

^.{2}$

Matches any string that is exactly 2 character(s) long.

string of exactly 3 characters

^.{3}$

Matches any string that is exactly 3 character(s) long.

string of exactly 4 characters

^.{4}$

Matches any string that is exactly 4 character(s) long.

string of exactly 5 characters

^.{5}$

Matches any string that is exactly 5 character(s) long.

string of exactly 6 characters

^.{6}$

Matches any string that is exactly 6 character(s) long.

string of exactly 8 characters

^.{8}$

Matches any string that is exactly 8 character(s) long.

string of exactly 10 characters

^.{10}$

Matches any string that is exactly 10 character(s) long.

string of exactly 12 characters

^.{12}$

Matches any string that is exactly 12 character(s) long.

string of exactly 16 characters

^.{16}$

Matches any string that is exactly 16 character(s) long.

string of exactly 20 characters

^.{20}$

Matches any string that is exactly 20 character(s) long.

string of exactly 32 characters

^.{32}$

Matches any string that is exactly 32 character(s) long.

string of exactly 64 characters

^.{64}$

Matches any string that is exactly 64 character(s) long.

2 letters only

^[A-Za-z]{2}$

Matches exactly 2 alphabetic letters (no digits).

3 letters only

^[A-Za-z]{3}$

Matches exactly 3 alphabetic letters (no digits).

4 letters only

^[A-Za-z]{4}$

Matches exactly 4 alphabetic letters (no digits).

5 letters only

^[A-Za-z]{5}$

Matches exactly 5 alphabetic letters (no digits).

6 letters only

^[A-Za-z]{6}$

Matches exactly 6 alphabetic letters (no digits).

8 letters only

^[A-Za-z]{8}$

Matches exactly 8 alphabetic letters (no digits).

10 letters only

^[A-Za-z]{10}$

Matches exactly 10 alphabetic letters (no digits).

6 to 10 digits

^\d{6,10}$

Matches a number between 6 and 10 digits long.

8 to 12 digits

^\d{8,12}$

Matches a number between 8 and 12 digits long.

3 to 5 digits

^\d{3,5}$

Matches a number between 3 and 5 digits long.

4 to 8 digits

^\d{4,8}$

Matches a number between 4 and 8 digits long.

10 to 15 digits

^\d{10,15}$

Matches a number between 10 and 15 digits long.