Regex Pattern Library

100 regular expressions you can copy and use today — for email addresses, URLs, dates, IP addresses, passwords, phone numbers, hex colours, and more. Every pattern comes with a token-by-token breakdown, test cases that should pass and should fail, the mistakes people make with it, performance notes, and a ready-to-paste snippet in twelve languages.

Nothing here fits? Build your own in theregex generator, or learn the syntax in theregular expressions guide.

EasyDates

24-Hour Time Regex

Validates a 24-hour clock time in HH:MM or HH:MM:SS format, such as 09:30 or 23:59:59.

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

Aadhaar Number Regex

Validates the format of an Indian Aadhaar 12-digit identity number, accepting either the compact digit-only form or the conventional space-grouped form like 1234 5678 9012.

^[2-9]\d{3}\s?\d{4}\s?\d{4}$
MediumSecurity

Base64 String Regex

Matches a standard Base64-encoded string, enforcing the correct alphabet, length multiple of four, and valid padding.

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

Basic Password Regex

Validates a simple password policy: 6-20 alphanumeric characters containing at least one letter and one digit, with no special-character or mixed-case requirements.

^(?=.*[A-Za-z])(?=.*\d)[A-Za-z0-9]{6,20}$
EasySecurity

Bearer Token Regex

Matches the value of an HTTP Authorization header using the Bearer scheme, such as 'Bearer <token>'.

^Bearer\s+[A-Za-z0-9\-_.]+$
EasyNumbers

Binary Number Regex

Validates that a string contains only the digits 0 and 1, i.e. a well-formed binary (base-2) number.

^[01]+$
EasyProgramming

camelCase Identifier Regex

Validates that a string is a lowerCamelCase identifier: it starts with a lowercase letter and each subsequent word begins with a single uppercase letter followed by lowercase letters or digits.

^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$
MediumValidation

Credit Card Number Regex

Validates the digit-only format of major credit card numbers by issuer prefix and length, covering Visa, MasterCard, American Express, and 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})$
MediumWeb

CSS Class Selector Regex

Validates a single CSS class selector: a leading dot followed by a legal CSS identifier, such as .btn, .btn-primary, or .btn_2, using ASCII letters, digits, underscores, and hyphens.

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

CSS Comment Regex

Detects a CSS comment, /* ... */, using a lazy quantifier so the match stops at the first closing */ instead of spanning all the way to the last one in the stylesheet.

/\*[\s\S]*?\*/
EasySecurity

CVV / CVC Code Regex

Validates a card verification value (CVV/CVC/CID) as exactly three or four digits, matching the security code formats used by Visa, Mastercard, and American Express.

^[0-9]{3,4}$
EasyNumbers

Decimal Number Regex

Validates a fixed-point decimal number that requires digits on both sides of the decimal point, with an optional leading minus sign.

^-?\d+\.\d+$
MediumNetworking

Domain Name Regex

Validates a fully qualified domain name made of one or more dot-separated labels followed by an alphabetic top-level domain, rejecting labels that start or end with a hyphen.

^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,63}$
EasyNetworking

Domain with TLD Regex

Validates a domain name that ends in a letters-only top-level domain of two or more characters, such as example.com, example.co.uk, or www.example.com.

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

Duplicate Spaces Regex

Matches two or more consecutive literal space characters, commonly used to collapse extra spacing down to a single space.

[ ]{2,}
MediumValidation

Email Regex

Validates common email address formats by requiring a local part, an @ symbol, a domain, and a top-level domain of at least two letters.

^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$
HardText Processing

Emoji Regex

Matches a single emoji character using the Unicode Extended_Pictographic property, which requires the u (or v) flag for Unicode property escapes.

\p{Extended_Pictographic}
EasyFiles

File Extension Regex

Extracts and validates the file extension of a filename, requiring at least one character before the final dot.

^.+\.([a-zA-Z0-9]+)$
MediumNumbers

Float Number Regex

Validates a floating-point literal that always contains a decimal point, allowing the digits before or after it to be omitted, similar to how many programming languages parse float literals.

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

Function Call / Name Regex

Matches a simple function-call-shaped string: a valid identifier immediately followed by a parenthesized, non-nested argument list, such as foo() or add(a, b).

^[A-Za-z_][A-Za-z0-9_]*\([^)]*\)$
MediumSecurity

Generic API Key Regex

Matches a generic API key shape: an optional underscore-separated prefix like sk_live_ followed by a 32-character or longer alphanumeric token.

^(?:[a-zA-Z0-9]+_)*[A-Za-z0-9]{32,}$
EasyProgramming

Generic Variable Name Regex

Validates a generic variable name shared by most C-family and scripting languages: it must start with a letter or underscore, followed by any number of letters, digits, or underscores.

^[a-zA-Z_][a-zA-Z0-9_]*$
MediumWeb

GitHub URL Regex

Matches a GitHub repository URL and captures the owner and repository name, optionally allowing a deeper path like a file or branch.

^https?:\/\/(?:www\.)?github\.com\/([\w.-]+)\/([\w.-]+)(?:\/.*)?$
EasyText Processing

Hashtag Regex

Validates a social-media style hashtag: a leading # symbol followed by a letter and then any combination of letters, digits, and underscores.

^#[A-Za-z][A-Za-z0-9_]*$
EasyWeb

Hex Color Code Regex

Validates a CSS hex color code in either the six-digit (#RRGGBB) or shorthand three-digit (#RGB) form.

^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$
MediumNumbers

Hexadecimal Number Regex

Validates a base-16 (hexadecimal) number that must be written with an explicit '0x' or '0X' prefix, followed by one or more hex digits.

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

Hostname Regex

Validates an RFC 1123 style hostname made of one or more dot-separated labels, where every label starts and ends with an alphanumeric character and may contain interior hyphens.

^[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$
MediumWeb

HTML Attribute Regex

Validates a single HTML attribute, matching a boolean attribute name on its own (like disabled), or a name=value pair using double-quoted, single-quoted, or unquoted attribute values.

^[a-zA-Z_:][-a-zA-Z0-9_:.]*(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?$
MediumWeb

HTML Comment Regex

Detects an HTML comment, <!-- ... -->, using a lazy quantifier so the match stops at the first closing --> instead of swallowing everything up to the last one in the document.

<!--[\s\S]*?-->
MediumWeb

HTML Tag Regex

Finds opening and closing HTML tags such as <div>, </span>, or <br/> by matching an angle bracket, an optional slash, a tag name, and any attributes up to the closing bracket.

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

Image URL Regex

Matches an absolute HTTP or HTTPS URL that ends in a common image file extension, with an optional query string.

^https?:\/\/\S+\.(?:jpg|jpeg|png|gif|webp|svg|bmp|avif)(?:\?\S*)?$
HardInternational

Indian GSTIN Regex

Validates the structural format of a 15-character Indian GST Identification Number (GSTIN): state code, embedded PAN, entity code, the fixed letter Z, and a checksum character.

^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$
EasyInternational

Indian PAN Number Regex

Validates the format of an Indian Permanent Account Number (PAN): five uppercase letters, four digits, and a final uppercase letter, e.g. ABCDE1234F.

^[A-Z]{5}[0-9]{4}[A-Z]$
EasyInternational

Indian PIN Code Regex

Validates a 6-digit Indian postal PIN code, requiring the first digit to be 1-9 since no PIN code region starts with 0.

^[1-9][0-9]{5}$
EasyNumbers

Integer Regex

Validates a whole number with an optional leading minus sign, disallowing decimal points and unnecessary leading zeros.

^-?(0|[1-9]\d*)$
EasyNetworking

IPv4 Address Regex

Validates a dotted-quad IPv4 address, ensuring each of the four octets is a number between 0 and 255 with no leading zeros.

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

IPv4 CIDR Notation Regex

Validates an IPv4 address in CIDR notation, ensuring each of the four octets falls within 0-255 and the prefix length after the slash falls within 0-32.

^(?:(?: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)\/(?:3[0-2]|[12]?\d)$
HardNetworking

IPv6 Address Regex

Validates a full or zero-compressed IPv6 address, including the double-colon (::) shorthand for one run of consecutive zero groups.

^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$
HardNetworking

IPv6 CIDR Notation Regex

Validates an IPv6 address written in CIDR (Classless Inter-Domain Routing) notation, such as 2001:db8::/32 or ::1/128, including the zero-compressed :: shorthand and a prefix length from 0 to 128.

^(?:(?:[0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}|(?:[0-9A-Fa-f]{1,4}:){1,7}:|(?:[0-9A-Fa-f]{1,4}:){1,6}:[0-9A-Fa-f]{1,4}|(?:[0-9A-Fa-f]{1,4}:){1,5}(?::[0-9A-Fa-f]{1,4}){1,2}|(?:[0-9A-Fa-f]{1,4}:){1,4}(?::[0-9A-Fa-f]{1,4}){1,3}|(?:[0-9A-Fa-f]{1,4}:){1,3}(?::[0-9A-Fa-f]{1,4}){1,4}|(?:[0-9A-Fa-f]{1,4}:){1,2}(?::[0-9A-Fa-f]{1,4}){1,5}|[0-9A-Fa-f]{1,4}:(?:(?::[0-9A-Fa-f]{1,4}){1,6})|:(?:(?::[0-9A-Fa-f]{1,4}){1,7}|:))\/(?:12[0-8]|1[01][0-9]|[1-9]?[0-9])$
MediumValidation

ISBN-10 / ISBN-13 Regex

Validates the compact, unformatted length and character shape of an ISBN-10 (9 digits plus a final digit or X) or an ISBN-13 (13 digits), without hyphens or spaces.

^(?:\d{9}[\dX]|\d{13})$
EasyInternational

ISO 3166-1 Alpha-2 Country Code Regex

Validates that a string has the shape of an ISO 3166-1 alpha-2 country code: exactly two uppercase letters, such as US, GB, or IN.

^[A-Z]{2}$
EasyInternational

ISO 4217 Currency Code Regex

Validates that a string has the shape of an ISO 4217 currency code: exactly three uppercase letters, such as USD, EUR, or INR.

^[A-Z]{3}$
MediumInternational

ISO 639-1 / BCP-47 Language Code Regex

Validates an ISO 639-1 two-letter language code, optionally followed by a BCP-47 style region subtag such as en-US or zh-CN.

^[a-z]{2}(-[A-Z]{2})?$
EasyDates

ISO 8601 Date Regex

Validates a calendar date in ISO 8601 YYYY-MM-DD format, checking that the month is 01-12 and the day is 01-31.

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

ISO 8601 Time Regex

Validates a 24-hour ISO 8601 time-of-day string in HH:MM:SS format, with an optional fractional-seconds component of up to three digits.

^([01]\d|2[0-3]):[0-5]\d:[0-5]\d(\.\d{1,3})?$
EasyProgramming

Java Identifier Regex

Validates that a string is a syntactically legal Java identifier: it must start with a letter, underscore, or dollar sign, followed by any number of letters, digits, underscores, or dollar signs.

^[A-Za-z_$][A-Za-z0-9_$]*$
MediumProgramming

JavaScript Comment Regex

Detects a JavaScript comment, either a single-line // comment or a block /* ... */ comment, using a lazy quantifier on the block form so it stops at the first closing */ instead of the last one.

\/\/.*|\/\*[\s\S]*?\*\/
MediumWeb

JSON Value Token Regex

Matches a single JSON scalar value: a double-quoted string, a JSON-formatted number, or one of the literals true, false, or null.

^(?:"(?:[^"\\]|\\.)*"|-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?|true|false|null)$
MediumSecurity

JWT (JSON Web Token) Regex

Checks that a string has the three-part, dot-separated base64url shape of a JSON Web Token (header.payload.signature) without decoding or verifying the signature.

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

kebab-case Identifier Regex

Validates that a string is a lower kebab-case identifier: lowercase words separated by single hyphens, with no leading, trailing, or doubled hyphens.

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

Latitude Regex

Validates a decimal latitude value within the real-world range of -90 to 90 degrees, with an optional fractional component of any precision.

^-?(90(\.0+)?|[1-8]?[0-9](\.[0-9]+)?)$
HardInternational

Latitude/Longitude Coordinate Pair Regex

Validates a comma-separated 'latitude,longitude' coordinate pair, enforcing the real-world ranges of -90 to 90 for latitude and -180 to 180 for longitude.

^-?(90(\.0+)?|[1-8]?[0-9](\.[0-9]+)?),\s*-?(180(\.0+)?|1[0-7][0-9](\.[0-9]+)?|[1-9]?[0-9](\.[0-9]+)?)$
EasyText Processing

Line Ending (Newline) Regex

Matches a single line ending in any common style: Windows CRLF (\r\n), classic Mac CR (\r), or Unix LF (\n).

\r\n|\r|\n
MediumWeb

LinkedIn URL Regex

Matches a LinkedIn personal profile, company page, or legacy public profile URL.

^https?:\/\/(?:www\.)?linkedin\.com\/(?:in|company|pub)\/[\w-]+\/?$
MediumInternational

Longitude Regex

Validates a decimal longitude value within the real-world range of -180 to 180 degrees, with an optional fractional component of any precision.

^-?(180(\.0+)?|1[0-7][0-9](\.[0-9]+)?|[1-9]?[0-9](\.[0-9]+)?)$
MediumNetworking

MAC Address Regex

Validates a 48-bit MAC address written as six hexadecimal byte pairs separated by colons or hyphens, such as 00:1A:2B:3C:4D:5E.

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

Markdown Link Regex

Matches Markdown link syntax [text](url) and captures the link text and destination, with optional support for a quoted title.

\[([^\]]+)\]\(([^)\s]+)(?:\s+"[^"]*")?\)
EasyText Processing

Mention Handle Regex

Validates a social-media style @mention handle: an @ symbol followed by 1 to 15 letters, digits, or underscores, matching common username length limits.

^@[A-Za-z0-9_]{1,15}$
EasyFiles

MIME Type Regex

Matches a MIME type string in the form type/subtype, such as text/html or application/json, including structured suffixes like +json.

^[a-zA-Z0-9!#$&^_.+-]+\/[a-zA-Z0-9!#$&^_.+-]+$
MediumValidation

Mobile Number Regex

Validates a 10-digit mobile number with an optional international dialing prefix such as +91 or +1, allowing a single space or hyphen between the country code and the number.

^(?:\+\d{1,3}[-\s]?)?\d{10}$
EasyNumbers

Octal Number Regex

Validates a base-8 (octal) number, accepting digits 0-7 with an optional case-insensitive '0o' prefix as used by modern language literals.

^(0o)?[0-7]+$
EasySecurity

One-Time Password (OTP) Regex

Validates that a string is a numeric one-time password between 4 and 8 digits long, matching the typical range used by SMS, email, and authenticator-app OTPs.

^\d{4,8}$
MediumInternational

Passport Number Regex

Validates a generic international passport number shape: a leading letter followed by 5 to 8 more letters or digits, for a total length of 6 to 9 alphanumeric characters.

^[A-Z][A-Z0-9]{5,8}$
EasyNumbers

Percentage Regex

Validates a percentage value: a signed integer or decimal number immediately followed by a trailing percent sign.

^-?\d+(\.\d+)?%$
MediumValidation

Phone Number Regex

Validates common North American phone number formats, accepting optional country code, parentheses, dots, dashes, or spaces as separators.

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

Protocol-Relative URL Regex

Validates a protocol-relative URL that omits the scheme and starts with //, such as //example.com/path, which inherits http or https from the page that references it.

^\/\/[\w-]+(\.[\w-]+)+(:\d+)?(\/[^\s]*)?$
EasyProgramming

Python Identifier Regex

Validates that a string is a syntactically legal Python identifier: it must start with an ASCII letter or underscore, followed by any number of letters, digits, or underscores.

^[A-Za-z_][A-Za-z0-9_]*$
MediumWeb

Relative URL Regex

Validates a root-relative URL path such as /path/to/page, including an optional query string and fragment, while rejecting protocol-relative (//host) and absolute URLs.

^\/(?!\/)[\w\-\/.]*(\?[^\s#]*)?(#[^\s]*)?$
HardNumbers

Roman Numerals Regex

Validates well-formed Roman numerals from 1 to 3999 written with standard subtractive notation (e.g. IV, IX, XL, XC, CD, CM).

^(?=[MDCLXVI])M{0,3}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$
HardNumbers

Scientific Notation Regex

Validates a number written in scientific (exponential) notation, such as 1.23e-10 or -6.022E23, with a mantissa, an e/E marker, and a signed integer exponent.

^-?\d+(\.\d+)?[eE][+-]?\d+$
HardProgramming

Semantic Version (SemVer) Regex

Validates a full Semantic Versioning 2.0.0 string, including major.minor.patch, optional prerelease identifiers, and optional build metadata, matching the official semver.org grammar.

^(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-]+)*))?$
EasyProgramming

snake_case Identifier Regex

Validates that a string is a lower_snake_case identifier: lowercase words separated by single underscores, with no leading, trailing, or doubled underscores.

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

SQL Identifier Regex

Validates a SQL identifier (table or column name) in any of its common forms: a plain unquoted identifier, a double-quoted identifier (ANSI SQL/PostgreSQL), a backtick-quoted identifier (MySQL), or a bracket-quoted identifier (SQL Server).

^(?:[A-Za-z_][A-Za-z0-9_]*|"[^"]*"|`[^`]*`|\[[^\]]*\])$
HardSecurity

Strong Password Regex

Validates that a password is at least 8 characters long and contains a lowercase letter, an uppercase letter, a digit, and a special character, using lookahead assertions.

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*])[A-Za-z\d!@#$%^&*]{8,}$
MediumNetworking

Subdomain Regex

Validates a hostname that includes at least one subdomain label in front of a base domain and top-level domain, such as www.example.com or api.staging.example.co.uk.

^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.){2,}[a-zA-Z]{2,}$
EasyText Processing

Tab Character Regex

Matches one or more consecutive tab characters, useful for detecting or converting tab-indented text.

\t+
HardNetworking

TCP/UDP Port Number Regex

Validates that a string is a valid TCP or UDP port number in the full range 0 to 65535, rejecting values outside that range and leading zeros.

^(6553[0-5]|655[0-2]\d|65[0-4]\d\d|6[0-4]\d{3}|[1-5]\d{4}|[1-9]\d{0,3}|0)$
MediumNumbers

Temperature Regex

Validates a temperature value made of a signed number, an optional space and degree symbol, and a unit letter for Celsius, Fahrenheit, or Kelvin.

^-?\d+(\.\d+)?\s?°?[CFK]$
MediumWeb

Twitter/X URL Regex

Matches a Twitter/X profile URL or an individual tweet (status) URL on either twitter.com or x.com, capturing the handle and optional tweet ID.

^https?:\/\/(?:www\.)?(?:twitter|x)\.com\/(\w{1,15})(?:\/status\/(\d+))?\/?$
MediumInternational

UK Postcode Regex

Validates a United Kingdom postcode across all standard outward-code formats (area + district) plus the fixed-format inward code, including the special GIR 0AA Girobank postcode.

^(GIR 0AA|((([A-Z][0-9]{1,2})|([A-Z][A-HJ-Y][0-9]{1,2})|([A-Z][0-9][A-Z])|([A-Z][A-HJ-Y][0-9][A-Z]?))\s?[0-9][A-Z]{2}))$
HardText Processing

Unicode Escape Sequence Regex

Matches JavaScript-style Unicode escape sequences, both the fixed 4-hex-digit form \uXXXX and the code-point brace form \u{XXXXX}.

\\u(?:[0-9A-Fa-f]{4}|\{[0-9A-Fa-f]{1,6}\})
EasyFiles

Unix File Path Regex

Validates an absolute Unix-style file path such as /home/user/file.txt, rejecting relative paths and double slashes.

^/(?:[^/]+/?)*$
EasyDates

Unix Timestamp Regex

Matches a numeric Unix epoch timestamp in either 10-digit seconds precision or 13-digit millisecond precision.

^\d{10}(\d{3})?$
MediumWeb

URL Query Parameter Regex

Matches a single key=value pair within a URL query string, where both the key and the (optionally empty) value contain only URL-safe characters.

[A-Za-z0-9_.~%+-]+=[A-Za-z0-9_.~%+-]*
MediumWeb

URL Regex

Validates HTTP and HTTPS URLs with a required host containing at least one dot, an optional port, and an optional path, query, or fragment.

^https?:\/\/[\w-]+(\.[\w-]+)+(:\d+)?([\/?#][^\s]*)?$
EasyText Processing

URL Slug Regex

Validates a URL-friendly slug made of lowercase letters and digits, with single hyphens allowed only between word groups (no leading, trailing, or doubled hyphens).

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

URL with Port Regex

Validates an HTTP or HTTPS URL that explicitly includes a port number after the hostname, with an optional path, query string, or fragment.

^https?:\/\/[a-zA-Z0-9.-]+:\d{2,5}(\/[^\s]*)?$
MediumDates

US Date Regex (MM/DD/YYYY)

Validates a calendar date in the US MM/DD/YYYY format with slash separators, requiring zero-padded month and day values.

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

US Dollar Currency Regex

Validates a US dollar amount with a leading dollar sign, comma-grouped thousands, and an optional two-digit cents portion, such as $1,234.56.

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

US Social Security Number Regex

Validates the format of a US Social Security Number (123-45-6789), rejecting area, group, and serial values that the SSA never issues, such as area 000, 666, or 900-999.

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

US ZIP Code Regex

Validates United States ZIP codes in both the standard 5-digit form and the extended ZIP+4 form (e.g. 12345-6789).

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

Username Regex

Validates that a username is 3 to 16 characters long and contains only letters, digits, underscores, or hyphens.

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

UUID Regex

Validates a standard 8-4-4-4-12 hyphenated UUID string, including the version nibble and RFC 4122 variant bits.

^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
MediumValidation

Vehicle Identification Number (VIN) Regex

Validates that a string is a 17-character Vehicle Identification Number using only the characters the VIN standard allows, excluding the letters I, O, and Q to avoid confusion with 1 and 0.

^[A-HJ-NPR-Z0-9]{17}$
EasyWeb

Video URL Regex

Matches an absolute HTTP or HTTPS URL that ends in a common video file extension, with an optional query string.

^https?:\/\/\S+\.(?:mp4|webm|mov|avi|mkv|flv|wmv)(?:\?\S*)?$
EasyText Processing

Whitespace Character Regex

Matches one or more consecutive whitespace characters, including spaces, tabs, newlines, carriage returns, form feeds, and vertical tabs.

[ \t\n\r\f\v]+
MediumFiles

Windows File Path Regex

Validates an absolute Windows file path such as C:\Users\name\file.txt, requiring a drive letter and rejecting reserved filename characters.

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

XML Tag Regex

Matches a single XML opening, closing, or self-closing tag, including any attributes with double- or single-quoted values.

<\/?[a-zA-Z_][\w:.-]*(?:\s+[a-zA-Z_:][\w:.-]*(?:=(?:"[^"]*"|'[^']*'))?)*\s*\/?>
MediumWeb

YAML Key-Value Line Regex

Matches a single YAML line of the form key: value, allowing for leading indentation and optional whitespace around the colon.

^\s*[A-Za-z_][\w-]*\s*:\s+.+$
MediumWeb

YouTube URL Regex

Matches standard, short (youtu.be), embed, and Shorts YouTube video URLs and validates the 11-character video ID.

^(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:watch\?v=|embed\/|shorts\/)|youtu\.be\/)[\w-]{11}(?:\S*)?$

Pattern Library Questions

Can I use these regex patterns in production?

Yes. Every pattern is documented with the inputs it accepts, the inputs it rejects, and the edge cases it deliberately does not cover, so you can judge whether it fits your case before shipping it. Read the limitations section on each page — a pattern that is right for a signup form is often wrong for a data-migration script.

Which programming languages are these patterns written for?

Every pattern page includes a ready-to-paste snippet for JavaScript, TypeScript, Node.js, Python, Java, C#, PHP, Go, Rust, Ruby, Kotlin, and Swift. The pattern itself is shared; where a language differs — Go's RE2 engine has no lookbehind or backreferences, for instance — the page says so under browser and engine compatibility.

How do I test one of these patterns against my own data?

Each pattern page has an embedded tester pre-loaded with the pattern, so you can paste your own text straight in. For a full workspace with flags, replace mode, and capture-group inspection, open the same pattern in the regex tester.

How are patterns organised?

By category — validation, web, text processing, security, identifiers, dates and numbers, and more — and by difficulty from Easy to Expert. Use the filters to narrow by both, or search by name, tag, or what the pattern matches.