Common Regex Patterns

Copy common regex patterns

Email Address

^[^\s@]+@[^\s@]+\.[^\s@]+$

Good enough for form validation (requires an @ and a dot in the domain); not a full RFC 5322 implementation.

URL

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

Matches most common http/https URLs with an optional path and query string; does not validate every edge case of the URL spec.

US Phone Number

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

Matches common US formats like (555) 123-4567, 555-123-4567, or 5551234567; does not validate area code ranges.

International Phone Number (E.164)

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

Matches E.164-style numbers such as +14155552671; it checks length and leading digit only, not real dialing plans.

IPv4 Address

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

Correctly restricts each octet to 0-255; does not check for reserved or private address ranges.

Hex Color

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

Matches 3-digit or 6-digit hex colors with an optional leading #; does not match 4/8-digit hex-with-alpha notation.

US ZIP Code

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

Matches 5-digit ZIP codes and the extended ZIP+4 format; does not verify the code corresponds to a real location.

Date (YYYY-MM-DD)

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

Checks the shape and basic month/day ranges (01-12, 01-31); does not know that April has 30 days or account for leap years.

Time (HH:MM, 24-hour)

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

Matches 24-hour times from 00:00 to 23:59; does not support 12-hour AM/PM format or seconds.

Strong Password

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

Requires at least 8 characters with a lowercase, uppercase, digit, and symbol; it checks composition only, not real-world password strength.

Username

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

Matches 3-16 letters, digits, or underscores; adjust the length and allowed characters to match your own rules.

HTML Tag

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

Matches simple, non-nested HTML tag pairs; regex cannot reliably parse arbitrary or nested HTML — use a real HTML parser for that.

Whitespace-Only String

^\s*$

Matches a string that is empty or contains only spaces, tabs, or newlines; useful for "required field" validation.

Integer

^-?\d+$

Matches whole numbers with an optional leading minus sign; does not enforce a specific numeric range.

Decimal Number

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

Matches integers and decimals with an optional minus sign; does not support scientific notation like 1e10.

What Is This Tool?

Common Regex Patterns is a library of ready-to-use regular expressions for everyday validation needs — emails, URLs, phone numbers, IP addresses, dates, and more. Each pattern comes with an honest description of what it does and does not cover, plus a one-click Copy button and a link to try it live in the Regex Tester.

How to Use

1

Find the pattern you need in the list.

2

Read the description to confirm it fits your use case and its limitations.

3

Click Copy to copy the pattern to your clipboard.

4

Paste it into your code, or click "Try in Regex Tester" to test it against sample text first.

Features

  • 15 ready-to-use patterns for common validation needs
  • Honest, plain-English notes on each pattern's limitations
  • One-click copy for every pattern
  • Direct links to test each pattern in the Regex Tester
  • 100% client-side — nothing leaves your browser

Examples

Email pattern ^[^\s@]+@[^\s@]+\.[^\s@]+$ matches ada@example.com but rejects ada@example (missing a dot in the domain).

US phone pattern ^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$ matches (555) 123-4567 and 555-123-4567.

Common Use Cases

  • Adding quick client-side or server-side validation to a form
  • Grabbing a starting point for a pattern instead of writing one from scratch
  • Learning how a well-formed regex for a common data type is structured
  • Sanity-checking data during a quick script or migration

Frequently Asked Questions

Are these patterns production-ready?

They're solid starting points for common validation needs, but each description notes what it doesn't cover. For anything security- or compliance-critical (like full email validation per RFC 5322), pair regex with a proper library or server-side check.

Why doesn't the email pattern catch every invalid email?

Full RFC 5322 email validation requires an extremely complex pattern that still can't verify an address is deliverable. This pattern covers the vast majority of real-world addresses for form validation purposes.

Which regex flavor are these patterns written in?

Standard JavaScript (ECMAScript) regex syntax, so they work directly in the browser, Node.js, and most modern languages with minor adjustments.

Can I test a pattern before using it?

Yes. Click "Try in Regex Tester" next to any pattern to test it against your own sample text.

Is any of this data sent to a server?

No. This is a static reference page. Copying a pattern uses your browser's clipboard API directly.

Why does the HTML tag pattern say it can't parse nested HTML?

Regular expressions aren't powerful enough to correctly parse arbitrarily nested markup. For real HTML parsing, use a DOM parser or a dedicated HTML parsing library instead.