Skip to main content

Common Regex Patterns Library

Common Regex Patterns is a searchable library of tested regular expressions for email, URL, phone, IP, dates, passwords and more. Copy verified patterns with one click.

Written & reviewed by Helperzy Editorial Team · Updated July 2026

Email address

Matches a standard email address. Pragmatic pattern suitable for form validation.

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

Example match: user.name@example.com

URL (http/https)

Matches HTTP and HTTPS URLs with optional path, query, and fragment.

Web
^https?:\/\/[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=]*$

Example match: https://example.com/path?q=1

Slug (URL-friendly)

Lowercase words separated by single hyphens, as used in URL slugs.

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

Example match: my-blog-post-2024

IPv4 address

Matches a valid IPv4 address with each octet between 0 and 255.

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

Example match: 192.168.1.1

MAC address

Matches a MAC address using colon or hyphen separators.

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

Example match: 01:23:45:67:89:AB

US phone number

Matches US phone numbers with optional country code and common separators.

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

Example match: +1 (555) 123-4567

Indian mobile number

Matches a 10-digit Indian mobile number starting 6-9, with optional +91.

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

Example match: +91 9876543210

Strong password

At least 8 chars with one lowercase, one uppercase, one digit, and one special char.

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

Example match: Passw0rd!

Username

Alphanumeric and underscore, 3 to 16 characters.

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

Example match: john_doe_99

Hex color

Matches 3-digit or 6-digit hexadecimal color codes.

Web
^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$

Example match: #6366f1

Date (YYYY-MM-DD)

Matches ISO 8601 style dates. Does not validate day-per-month exactness.

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

Example match: 2024-02-29

Time (24-hour HH:MM)

Matches 24-hour clock time from 00:00 to 23:59.

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

Example match: 14:30

Time (12-hour with AM/PM)

Matches 12-hour time with an AM or PM suffix.

Date
^(?:1[0-2]|0?[1-9]):[0-5]\d\s?(?:[AaPp][Mm])$

Example match: 2:30 PM

Credit card (major issuers)

Matches Visa, Mastercard, American Express, and Discover card numbers.

Validation
^(?: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})$

Example match: 4111111111111111

Postal code (US ZIP)

Matches a 5-digit US ZIP code with an optional 4-digit extension.

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

Example match: 90210-1234

Indian PIN code

Matches a 6-digit Indian postal PIN code not starting with zero.

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

Example match: 560001

Whitespace (leading/trailing)

Matches leading and trailing whitespace, useful for trimming.

Text
^\s+|\s+$

Example match: hello

Number (integer or decimal)

Matches a signed integer or decimal number.

Text
^-?\d+(?:\.\d+)?$

Example match: -42.75

HTML tag

Matches opening and closing HTML tags with optional attributes.

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

Example match: <div class="box">

IPv6 address

Matches a fully expanded IPv6 address (eight groups of hex).

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

Example match: 2001:0db8:85a3:0000:0000:8a2e:0370:7334

100% Private

This pattern library runs entirely in your browser. Nothing uploaded.

How to Use Common Regex Patterns

1

Search or Filter

Search by name, description or the pattern text, or narrow to a category such as web, network, phone or date to see only the relevant entries.

2

Check the Example

Read the sample string each pattern accepts and confirm it covers your real data, including any local rules a generic pattern cannot know about.

3

Copy the Pattern

Copy it into a regex literal where possible. If you must put it in a quoted string, double every backslash or the pattern will match the wrong thing.

What This Regex Pattern Library Covers and How to Use It

Almost every application validates the same handful of things: email addresses, phone numbers, URLs, IP addresses, dates, postcodes and password strength. Almost every developer writes those patterns again from memory, gets one character wrong, and finds out in production. This library collects tested patterns for those cases with a description, a sample string each one accepts, and a copy button. You can search by name, by description or by the pattern text itself, and filter by category such as web, network, phone or date. It is a reference rather than a tester, which is a different job from building a pattern from scratch and debugging it character by character. Each entry is written with a specific intent, and understanding the anchoring is the key to using them correctly. A pattern that begins with a caret and ends with a dollar sign must match the entire string, which is exactly what you want when validating one field: an email input either is a valid address or it is not. Remove those two anchors and the same pattern becomes a search expression that will happily find a match buried inside a longer document, which is what you want when extracting values from a log file. Choosing wrongly here is the single most common misuse, because an unanchored validation pattern will accept a string that merely contains something valid, letting an entire malicious payload through around it. Take the email case concretely. A pragmatic pattern anchors at both ends, allows one or more characters from a set of letters, digits, dots, plus signs and hyphens for the local part, requires a single at sign, then allows a domain of letters, digits and hyphens followed by at least one dot and a suffix. Test it against asha.nair+news at example.co.in and it matches, because the plus sign and the multi-part suffix are both permitted. Test it against a string with two at signs and it fails. Test it against the sentence please email me at asha@example.com today and an anchored pattern correctly refuses, because the whole string is not an address, while an unanchored one would match the middle. That third case is the one worth trying yourself. Where a library beats memory. A developer building a signup form takes the email and password patterns rather than inventing them, saving an hour of edge-case testing. Someone parsing an nginx access log grabs the IPv4 pattern to pull out client addresses. A team validating Indian mobile numbers starts from the phone pattern and adjusts it to require a leading digit between 6 and 9, which is a local rule no generic pattern knows about. A data analyst cleaning a spreadsheet uses the date pattern to find rows that do not follow the expected year-month-day format before importing. A reviewer checks a colleague pattern against the library version and spots a missing anchor. Two caveats worth stating. These are pragmatic patterns, not standards implementations: the email specification permits addresses so unusual that a fully compliant pattern is hundreds of characters long and rejects nothing useful in practice, so the sensible approach is a simple format check plus a confirmation email. Do not treat a regex pass as proof an address exists. The other point is escaping when you embed a pattern in code: inside a quoted string literal each backslash must itself be escaped, so a digit class written with one backslash in the pattern needs two in the string, and forgetting that produces a pattern that silently matches the wrong thing. Prefer a regex literal where your language offers one. Searching and copying happen entirely in your browser and nothing is sent anywhere.

Examples: Common Regex Patterns

Input

Email pattern (anchored) tested against asha.nair+news@example.co.in

Result

Match — the plus sign in the local part and the two-part suffix are both allowed

The local-part character class includes plus and dot, and the domain portion permits multiple dot-separated labels, which is why a co.in address validates correctly.

Input

The same anchored pattern tested against: please email me at asha@example.com today

Result

No match

The caret and dollar anchors require the whole string to be an address; removing them would match the middle, which is exactly the mistake that lets junk through validation.

Frequently Asked Questions – Common Regex Patterns

Yes. Every pattern in the library has been checked against example inputs to confirm it matches what it should and rejects what it should not. They are written for practical validation, so you can copy and use them directly, though you should always test against your own specific data as a final step.