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)

web

Validates standard user email addresses with username, domain, and TLD.

Match example: alex.dev@example.com
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
Test

HTTP / HTTPS URL

web

Matches standard web URLs starting with http:// or https:// with query parameters.

Match example: 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()@:%_\+.~#?&\/=]*)$
Test

URL Slug / Kebab-case

web

Matches clean, SEO-friendly URL slugs separated by single hyphens.

Match example: json-to-typescript
^[a-z0-9]+(?:-[a-z0-9]+)*$
Test

Hex Color Code (#RGB or #RRGGBB)

web

Validates 3 or 6 digit hexadecimal CSS color representations.

Match example: #3b82f6
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$
Test

Strong Password Policy

security

Requires at least 8 characters, 1 uppercase, 1 lowercase, 1 number, and 1 special symbol.

Match example: P@ssw0rd2026!
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$
Test

UUID v4 Identifier

security

Matches 128-bit RFC 4122 version 4 cryptographically random UUIDs.

Match example: 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}$
Test

JSON Web Token (JWT)

security

Validates 3-part base64url encoded compact JSON Web Tokens.

Match example: eyJhbGciOi...eyJzdWIi...dozG48
^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$
Test

IPv4 Address

network

Matches standard dotted decimal IPv4 addresses (0.0.0.0 to 255.255.255.255).

Match example: 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]?)$
Test

IPv6 Address (Compressed or Full)

network

Validates full and colon-compressed 128-bit IPv6 address notations.

Match example: 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})$
Test

MAC Address (Colon or Hyphen)

network

Matches 48-bit hardware network interface MAC addresses.

Match example: 00:1A:2B:3C:4D:5E
^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$
Test

ISO 8601 Date (YYYY-MM-DD)

format

Matches standard international calendar date format.

Match example: 2026-10-06
^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$
Test

Semantic Versioning (SemVer)

format

Validates Major.Minor.Patch semantic version strings with optional prerelease tags.

Match example: 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-]+)*))?$
Test

Credit Card (Luhn digits 13-19)

format

Matches Visa, MasterCard, Amex, and Discover card number lengths and prefixes.

Match example: 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})$
Test

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.

Open Regex Tester