BizTechLab

IDEASINNOVATIONIMPACT

Regex

Common Patterns Library

Copy-ready regex patterns for email, URLs, IPv4/IPv6, dates, numbers, and more — each verified against its own example. Runs entirely in your browser.

18 patterns

Contact & Identity

Email Address

A reasonably strict email shape: local part, @, domain, TLD.

^[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}$

Example: jane.doe@example.com

URL (http/https)

An http or https URL with a domain and optional path.

^https?:\/\/[\w.-]+(?:\.[a-zA-Z]{2,})+(?:\/[^\s]*)?$

Example: https://example.com/path

US Phone Number

US-style phone number, with optional area code parentheses and separators.

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

Example: (555) 123-4567

Username

Letters, digits, and underscores, 3 to 16 characters.

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

Example: rajnish_k

UUID (v4)

/i

A version-4 UUID, the most common form used for generated IDs.

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

Example: 550e8400-e29b-41d4-a716-446655440000

Network

IPv4 Address

A valid IPv4 address (each octet checked to be 0-255, not just any digits).

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

Example: 192.168.1.1

IPv6 Address (full form)

A fully-written IPv6 address, eight groups of 1-4 hex digits.

^([\da-fA-F]{1,4}:){7}[\da-fA-F]{1,4}$

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

Doesn't handle the :: zero-compression shorthand — only matches addresses written out in full.

Dates & Time

ISO Date (YYYY-MM-DD)

Checks the shape of an ISO 8601 date, not that the date is real (e.g. 2026-02-31 still matches).

^\d{4}-\d{2}-\d{2}$

Example: 2026-07-30

24-Hour Time (HH:MM)

A valid 24-hour clock time.

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

Example: 14:30

Numbers & Formats

Integer

A whole number, with an optional leading + or -.

^[+-]?\d+$

Example: -42

Decimal Number

An integer or decimal number, with an optional leading + or -.

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

Example: 3.14

Hex Color

A 3- or 6-digit hex color code, with the leading #.

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

Example: #1a2b3c

US ZIP Code

A 5-digit ZIP code, with an optional 4-digit ZIP+4 suffix.

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

Example: 94105-1234

Credit Card Number (basic)

13-19 digits, optionally grouped with spaces or dashes — shape only, not a Luhn checksum.

^(?:\d[ -]?){13,19}$

Example: 4111 1111 1111 1111

Only checks digit count and grouping — it doesn't validate the card number's checksum, so it will match plausible-looking but fake numbers too.

Web & Text

URL Slug

Lowercase words separated by single hyphens — the shape used for URL-friendly identifiers.

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

Example: my-blog-post-title

HTML Tag (basic)

/is

A single HTML element with matching open/close tags and simple content.

<([a-z][a-z0-9]*)\b[^>]*>(.*?)<\/\1>

Example: <p>Hello</p>

Regex can't reliably parse nested or malformed HTML — use a real HTML parser for anything beyond a quick one-off match.

Whitespace-Only String

A string containing only spaces, tabs, or line breaks (including an empty string).

^\s*$

Example:

Security

Strong Password

At least 8 characters, with a lowercase letter, an uppercase letter, a digit, and a symbol.

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\w\s]).{8,}$

Example: P@ssw0rd!

Quick Learn

Most regex needs at work aren't novel — "validate an email," "match a hex color," "check a UUID" are things thousands of developers have already solved, usually the same way. Writing one from scratch every time means re-discovering the same edge cases (does the email pattern handle a plus sign? does the phone pattern require the area code parentheses?) that a well-tested pattern has already settled.

This library is a set of ready-to-paste patterns for the shapes that come up constantly: contact info, network addresses, dates, numeric formats, and common text/security checks. Every pattern here has been checked against its own example and against known-bad counterexamples it should reject, so what you copy is verified to do what its description says — not just something that "looked right."

Best Practices

  • Read the caveat on a pattern before trusting it in production — a few of these (HTML tags, credit card numbers) check shape only, not full correctness, and say so explicitly.
  • "Matches the shape" isn't the same as "is valid" — the ISO Date pattern accepts 2026-02-31 (not a real date) because checking calendar validity needs actual date logic, not just a regex.
  • Paste a pattern into the Regex Tester tool with your own real-world examples before shipping it — a library pattern is a strong starting point, not a guarantee it fits every edge case your data actually has.
  • Prefer the narrowest pattern that covers your real requirement — e.g. the basic Username pattern here won't accept accented letters, which may or may not be what you want depending on your users.

More Regex Tools

See all Regex tools

Frequently Asked Questions

Each pattern has been tested against its own example (to confirm it matches what it claims to) and against several known-bad inputs (to confirm it doesn't over-match) — but no regex pattern is a substitute for testing against your own real data before relying on it.

Want the engineering deep-dives behind tools like this one?