Regex Pattern Library

Common regex patterns ready to copy and use.

Ready-to-use patterns

Email

Matches valid email addresses

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

URL

Matches HTTP/HTTPS URLs

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

Phone (US)

US phone number formats

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

Phone (Intl)

International phone (E.164)

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

Credit Card

Visa, MasterCard, Amex

^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13})$

IPv4

IPv4 address

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

Hex Color

CSS hex color

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

Alphanumeric

Letters and numbers only

^[a-zA-Z0-9]+$

Letters Only

Letters only

^[a-zA-Z]+$

Numbers Only

Digits only

^\d+$

No Whitespace

No whitespace characters

^\S+$

Slug

URL slug format

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

Username

Alphanumeric username

^[a-zA-Z][a-zA-Z0-9_]{2,15}$

Strong Password

Min 8 chars, upper, lower, digit, special

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

Medium Password

Min 6 chars, upper, lower, digit

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

Date (YYYY-MM-DD)

ISO date format

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

Date (MM/DD/YYYY)

US date format

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

Time (24h)

24-hour time

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

Time (12h)

12-hour time

^(?:0?[1-9]|1[0-2]):[0-5]\d\s?(?:AM|PM|am|pm)$

HTML Tag

HTML opening/closing tags

<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)

CSS Class

CSS class selector

\.[a-zA-Z_][a-zA-Z0-9_-]*

JS Variable

Valid JS variable name

^[a-zA-Z_$][a-zA-Z0-9_$]*$

UUID

UUID v4 format

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

💡 Use the Regex Tester to test these patterns

About

About the Regex Pattern Library

The Regex Library is a curated collection of 28 ready-to-use regular expressions for the things people actually need to match: email addresses, URLs, US and international phone numbers, credit cards, IPv4 addresses, hex colors, dates, times, password rules, and common text and code patterns. Each entry shows the pattern with a plain-English description of what it matches, organised by category with instant search — find it, copy it, paste it into your code. No more reconstructing an email regex from memory at 11pm.

How to use the Regex Pattern Library

  1. 1Search for what you need — "email", "phone", "IP" — or browse by category.
  2. 2Read the description to confirm the pattern matches what you expect.
  3. 3Copy the pattern with one click.
  4. 4Paste it into your language's regex call (escaping rules differ slightly per language).
  5. 5Test it against your real data — our regex tester is one tab away.

Common use cases

  • Grabbing a proven email or URL validation pattern for a form
  • Validating phone numbers in E.164 format before sending SMS
  • Matching IPv4 addresses or hex colors in logs and stylesheets
  • Enforcing a password policy pattern in a signup flow
  • Learning regex by reading real patterns with plain-English explanations

Frequently asked questions

What patterns are included?

28 patterns across five categories: validation (email, URL, US and E.164 international phone, credit card, IPv4, hex color), text matching, code-related patterns, dates and times, and password rules — the recurring 95% of real-world regex needs.

Will these patterns work in my programming language?

The patterns use widely supported syntax that works in JavaScript, Python, Java, PHP, and most modern engines. What differs per language is how you write the pattern down — quoting and backslash escaping — so paste the pattern into your language's normal regex literal or string and adjust escapes if the compiler complains.

Is a regex enough to fully validate an email address?

It's the right first line of defence — catching typos and obvious garbage — but the only true validation is sending a confirmation. A pragmatic pattern like this one intentionally rejects some exotic-but-legal addresses in exchange for matching what users actually type.

Can I test a pattern before using it?

Yes — copy any pattern into our regex tester tool to try it against your own sample text live, see the matches highlighted, and tweak it safely.