Skip to main content

Regex Pattern Library

v1.0.0

Browse a curated library of common regular expression patterns organised by category.

32 patterns found

Email Address

Validation

Basic RFC-5321-compatible email validation.

/^[\w.%+\-]+@[\w.\-]+\.[a-zA-Z]{2,}$/i

URL (http/https)

URL

Match http and https URLs.

/^https?:\/\/[\w\-]+(\.[\w\-]+)+([\w\-.,@?^=%&:/~+#]*[\w\-@?^=%&/~+#])?$/i

IPv4 Address

IP

Match valid IPv4 addresses.

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

IPv6 Address

IP

Match full-form IPv6 addresses.

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

ISO 8601 Date

Date

YYYY-MM-DD format.

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

International Phone

Phone

E.164 international phone number format.

/^\+?[1-9]\d{1,14}$/

Hex Color

Validation

CSS hex color codes (3, 6, or 8 hex digits with #).

/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/i

German Postal Code

Postal

German 5-digit postal code.

/^[0-9]{5}$/

US ZIP Code

Postal

US 5-digit or ZIP+4 postal code.

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

Credit Card Number

Validation

Major card types: Visa, Mastercard, Amex, Discover.

/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|6(?:011|5[0-9]{2})[0-9]{12})$/

UUID v4

Validation

RFC 4122 UUID version 4.

/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i

URL Slug

URL

Lowercase alphanumeric slug with hyphens.

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

Strong Password

Validation

Minimum 12 chars, upper+lower+digit+special.

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

Username

Validation

3–20 chars, starts with letter, allows _ and -.

/^[a-zA-Z][a-zA-Z0-9_\-]{2,19}$/

HTML Tag

Parsing

Match opening HTML tags.

/<([a-zA-Z][a-zA-Z0-9]*)\b[^>]*>/g

IBAN

Validation

Basic IBAN structure validation.

/^[A-Z]{2}\d{2}[A-Z0-9]{1,30}$/

MAC Address

Network

MAC address with : or - separator.

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

CIDR Notation

Network

IPv4 CIDR block notation.

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

Semantic Version

Validation

semver 2.0.0 specification.

/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z][\w]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z][\w]*))*))?(?:\+([\w]+(\.[\w]+)*))?$/

JWT Token

Validation

Three-part base64url JWT structure.

/^[A-Za-z0-9_\-]+\.[A-Za-z0-9_\-]+\.[A-Za-z0-9_\-]*$/

Unix Timestamp

Date

10-digit Unix epoch timestamp (1973–2286).

/^[1-9]\d{8,9}$/

Docker Image Name

Parsing

Docker image with optional registry, namespace and tag.

/^(?:[a-z0-9]+(?:[._\-][a-z0-9]+)*\/)*[a-z0-9]+(?:[._\-][a-z0-9]+)*(?::[\w.\-]+)?$/

CSS Class Name

Parsing

Valid CSS class identifier.

/^\.?-?[_a-zA-Z]+[_a-zA-Z0-9\-]*$/

Unix File Path

Parsing

Absolute Unix file path.

/^(\/[^\/\x00]+)+\/?$/

Windows File Path

Parsing

Absolute Windows file path.

/^[a-zA-Z]:\\(?:[^\\/:*?"<>|\r\n]+\\)*[^\\/:*?"<>|\r\n]*$/i

YouTube Video ID

URL

11-character YouTube video identifier.

/^[a-zA-Z0-9_\-]{11}$/

Base64 String

Encoding

Standard Base64 encoded string.

/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{4})$/

Hexadecimal String

Encoding

Hexadecimal digits, optionally prefixed with 0x.

/^(0x)?[0-9a-fA-F]+$/i

JSON Object (starts/ends with {})

Parsing

Rough detection that a string looks like a JSON object.

/^\s*\{[\s\S]*\}\s*$/

Time HH:MM

Date

24-hour time format.

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

Currency Amount

Numbers

US currency format with optional cents.

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

US Social Security Number

Validation

US SSN format (dashes required).

/^(?!000|9\d{2}|666)\d{3}-(?!00)\d{2}-(?!0000)\d{4}$/