Regex Patterns Cheat Sheet
Production-ready regular expressions for validation, web parsing, and security.
What is a Regular Expression (RegEx)?
A regular expression (regex) is a sequence of characters defining a search pattern used by text search algorithms and parser engines. Formally standardized across POSIX, PCRE, and ECMAScript specifications, regex syntax utilizes literal characters, character classes, anchors (^, $), and quantifiers (*, +, ?) to validate user inputs, extract substrings, and perform string replacements.
Email Address (RFC 5322 General)
Validates standard user email addresses with username, domain, and TLD.
alex.dev@example.com^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$HTTP / HTTPS URL
Matches standard web URLs starting with http:// or https:// with query parameters.
https://devtoolkit-hub.vercel.app/tools^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$URL Slug / Kebab-case
Matches clean, SEO-friendly URL slugs separated by single hyphens.
json-to-typescript^[a-z0-9]+(?:-[a-z0-9]+)*$Hex Color Code (#RGB or #RRGGBB)
Validates 3 or 6 digit hexadecimal CSS color representations.
#3b82f6^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$Strong Password Policy
Requires at least 8 characters, 1 uppercase, 1 lowercase, 1 number, and 1 special symbol.
P@ssw0rd2026!^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$UUID v4 Identifier
Matches 128-bit RFC 4122 version 4 cryptographically random UUIDs.
9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$JSON Web Token (JWT)
Validates 3-part base64url encoded compact JSON Web Tokens.
eyJhbGciOi...eyJzdWIi...dozG48^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$IPv4 Address
Matches standard dotted decimal IPv4 addresses (0.0.0.0 to 255.255.255.255).
192.168.1.1^(?:(?: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]?)$IPv6 Address (Compressed or Full)
Validates full and colon-compressed 128-bit IPv6 address notations.
2001:0db8:85a3:0000:0000:8a2e:0370:7334^(([0-9a-fA-F]{1,4}:){7,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})$MAC Address (Colon or Hyphen)
Matches 48-bit hardware network interface MAC addresses.
00:1A:2B:3C:4D:5E^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$ISO 8601 Date (YYYY-MM-DD)
Matches standard international calendar date format.
2026-10-06^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$Semantic Versioning (SemVer)
Validates Major.Minor.Patch semantic version strings with optional prerelease tags.
16.2.9-beta.1^(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-]+)*))?$Credit Card (Luhn digits 13-19)
Matches Visa, MasterCard, Amex, and Discover card number lengths and prefixes.
4111111111111111^(?: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})$Frequently Asked Questions
How do I validate an email address with regular expressions?+
Use the RFC 5322 general pattern: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$. It validates that the username contains alphanumeric characters or allowable punctuation, followed by an '@' sign, a valid domain host, and at least a 2-letter top-level domain.
How does a strong password regex enforce complexity?+
Password patterns utilize positive lookaheads: '(?=.*[a-z])' checks for a lowercase letter, '(?=.*[A-Z])' checks for uppercase, '(?=.*\d)' checks for a digit, and '(?=.*[@$!%*?&])' checks for a symbol, alongside a minimum quantifier such as '{8,}'.
What is the difference between greedy and lazy quantifiers in Regex?+
Greedy quantifiers (like '.*') match the longest possible string that satisfies the pattern. Appending a question mark (like '.*?') creates a lazy/non-greedy quantifier that stops matching at the earliest possible instance.
How do I match an IPv4 address accurately in Regex?+
A true IPv4 regex must validate decimal ranges between 0 and 255 per octet: ^(?:(?: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]?)$.
Testing your pattern against sample strings?
Test regular expressions live with match highlighting, capture groups, and flag toggles in our client-side tester.