Skip to main content
Developer & Security 3 min read

Regex Cheat Sheet 2026: Common Patterns for Email, URL, Phone & More

A practical regex cheat sheet with copy-paste patterns for the most common validation tasks — email, URL, phone number, date, IP address, and more. Includes explanations and test examples.

MD
Meet Dhameliya
· Updated Oct 24, 2026

Regular expressions are one of the most powerful tools in a developer's toolkit — and one of the most frustrating to write from scratch. You know the pattern exists, you've written it before, and yet every time you need to validate an email address or extract a URL, you end up on Stack Overflow searching for the same regex.

This cheat sheet is designed to end that cycle. Patterns below are starting points to test against your own valid and invalid examples. Use our Regex Tester to try any pattern with your own test strings.

Email Address Validation

Basic pattern:

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

This matches standard email formats like user@domain.com, first.last@company.co.uk, and user+tag@gmail.com.

What it checks: One or more alphanumeric characters (plus dots, underscores, percent, plus, hyphen) before the @, followed by a domain name with at least one dot and a TLD of 2+ characters.

Edge cases it handles: Subdomains (user@mail.company.com), plus-addressing (user+tag@gmail.com), hyphens in domains.

What it doesn't handle: Quoted local parts ("user name"@domain.com), IP address domains (user@[192.168.1.1]), and some valid but uncommon formats. For 99% of form validation, this pattern is sufficient.

URL Validation

Pattern (HTTP/HTTPS):

^https?:\/\/([\w-]+\.)+[\w-]+(\/[\w\-./?%&=]*)?$

Matches URLs like https://example.com, http://sub.domain.co.uk/path?key=value, and https://api.example.com/v2/users.

Phone Number Patterns

International format (E.164):

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

Matches: +14155552671, +919876543210, +442071234567

Indian mobile number:

^(?:\+91|91|0)?[6-9]\d{9}$

Matches: +919876543210, 09876543210, 9876543210, 6123456789

US phone number:

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

Matches: (555) 123-4567, 555-123-4567, +15551234567, 555.123.4567

Password Strength Validation

Pattern (minimum 8 chars, uppercase, lowercase, digit, special char):

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

This uses lookaheads to assert the presence of each required character type without enforcing a specific order. Test your regex against sample passwords using our Regex Tester.

Date Format Patterns

DD/MM/YYYY:

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

YYYY-MM-DD (ISO 8601):

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

Note: These validate format only — they don't catch invalid dates like 31/02/2026. For full date validation, parse with your language's date library after regex matching.

IP Address Patterns

IPv4:

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

Matches valid IPv4 addresses (0.0.0.0 to 255.255.255.255) and rejects invalid octets like 256.1.1.1.

HTML Tag Extraction

Match opening HTML tags:

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

Match content between specific tags:

<title>(.*?)<\/title>

Important caveat: Regex should not be used to parse complex or nested HTML. Use a proper HTML parser (DOMParser, BeautifulSoup, Cheerio) for anything beyond simple tag extraction. Regex is fine for quick searches in known, simple HTML structures.

Common Text Patterns

Remove all HTML tags:

<[^>]*>

Match whitespace-only lines:

^\s*$

Extract numbers from text:

\d+\.?\d*

Match hex color codes:

#(?:[0-9a-fA-F]{3}){1,2}\b

Try all of these patterns with real text in our Regex Tester — it lists matching text and shows a preview; it does not provide a separate capture-group inspector.

Regex Flags Quick Reference

FlagNameEffect
gGlobalFind all matches, not just the first
iCase-insensitiveA matches both 'a' and 'A'
mMultiline^ and $ match start/end of each line, not just the string
sDotall. matches newline characters too
uUnicodeEnables Unicode-aware matching

Frequently Asked Questions

What is the best regex for email validation? expand_more
For most applications, ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ is sufficient. It catches 99% of valid email addresses. The RFC 5322 compliant regex is extremely complex and rarely needed. For production use, combine basic regex validation with an actual email verification step (send a confirmation email).
Why shouldn't I use regex to parse HTML? expand_more
HTML is a nested, context-sensitive language that regex (which handles regular languages) cannot fully parse. Regex fails on nested tags, attributes containing >, CDATA sections, comments, and malformed HTML. For simple extraction (finding all URLs in anchor tags), regex works. For anything involving document structure, use a DOM parser.
What does the ? after * or + mean in regex? expand_more
Adding ? after a quantifier (*?, +?, ??) makes it 'lazy' or 'non-greedy' — it matches the minimum possible characters instead of the maximum. For example, in the string 'bold text more', the greedy pattern .* matches everything from the first to the last , while .*? matches each ... pair separately.
How do I test regex patterns online? expand_more
Use our Regex Tester — paste your pattern, enter test strings, and see matches highlighted in real-time. It shows captured groups, explains match results, and supports all JavaScript regex flags (g, i, m, s, u). No login or installation required.

Related guides

build Try These Free Tools

Put what you learned into practice — no signup required

MD

Meet Dhameliya

Founder & Product Manager

Computer Engineering graduate with 3+ years in IT. Meet built Utility Spark to create privacy-first browser tools that process your data locally — no uploads, no accounts.