Regex Library

Browse, search, and test common regex patterns — copy with one click.

Email Address

Validates standard email addresses

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

URL

Matches HTTP/HTTPS URLs

https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)

Phone (International)

E.164 international phone format

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

Phone (US)

US phone numbers with optional formatting

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

IPv4 Address

Validates IPv4 addresses (0.0.0.0 - 255.255.255.255)

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

IPv6 Address

Matches full IPv6 addresses

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

MAC Address

Matches MAC addresses

([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})

Credit Card

Visa, Mastercard, Amex, Discover

\b(?:4\d{12}(?:\d{3})?|5[1-5]\d{14}|3[47]\d{13}|6(?:011|5\d{2})\d{12})\b

Hex Color

Matches 3 or 6 digit hex colors

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

HTML Tags

Matches opening and closing HTML tags

<\/?[a-z][\s\S]*?>

Quoted String

Matches single or double quoted strings

"([^"\\]|\\.)*"|'([^'\\]|\\.)*'

Slug

URL-friendly slug format

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

Whitespace Trim

Matches leading/trailing whitespace

^\s+|\s+$

Duplicate Words

Finds repeated consecutive words

\b(\w+)\s+\1\b

Integer

Positive or negative integers

^-?\d+$

Decimal Number

Decimal/float numbers

^-?\d*\.\d+$

Date (YYYY-MM-DD)

ISO 8601 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 (HH:MM)

24-hour time format

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

Currency

US dollar amounts

\$\d{1,3}(,\d{3})*(\.\d{2})?

Strong Password

Min 8 chars, upper, lower, digit, special

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

UUID v4

UUID version 4 format

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

JWT Token

JSON Web Token format

eyJ[A-Za-z0-9-_]+\.eyJ[A-Za-z0-9-_]+\.[A-Za-z0-9-_.+/=]+

Base64

Base64 encoded string

^[A-Za-z0-9+/]+=*$

JS Variable

Valid JavaScript variable name

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

Semver

Semantic versioning (major.minor.patch)

\bv?\d+\.\d+\.\d+(?:-[\w.]+)?(?:\+[\w.]+)?\b

Import Statement

ES module import statements

import\s+(?:{[^}]+}|\w+)\s+from\s+['"][^'"]+['"]

CSS Class

CSS class selectors

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

Single-line Comment

JS/TS single-line comments

\/\/.*$
29 / 29 patterns shown

What It Does

A curated, searchable collection of production-ready regular expressions organized by category. Find the pattern you need, test it against your own input in the live tester, and copy it to your clipboard. No need to write complex regex from scratch or hunt through documentation.

Pattern Categories

  • Validation — Email, URL, phone number, IPv4/IPv6, credit card number
  • Strings & Text — HTML tags, quoted strings, URL slugs, whitespace normalization
  • Numbers & Dates — Integers, floats, ISO 8601 dates, currency amounts
  • Security — Strong passwords, UUID v4, JWT tokens, Base64 strings
  • Programming — Variable names, semantic versioning, import/require statements

Regex Quick Reference

  • . Any char   \d Digit   \w Word char   \s Whitespace
  • ^ Start   $ End   \b Word boundary
  • * 0+   + 1+   ? 0 or 1   {n,m} n to m times
  • [abc] Character class   [^abc] Negated class
  • (abc) Capture group   (?:abc) Non-capturing group
  • a|b Alternation   (?=abc) Lookahead

Tips for Using Regex in Production

  • Anchor patterns with ^ and $ for validation — otherwise a pattern can match a substring of invalid input.
  • Avoid catastrophic backtracking — nested quantifiers like (a+)+ can hang on adversarial input (ReDoS attack).
  • Use named capture groups ((?<year>\d4)) for readability in complex extraction patterns.
  • Always validate email addresses by sending a confirmation message — no regex fully covers RFC 5322.

Frequently Asked Questions

What regex patterns are included in this library?
The library covers five categories: Validation (email, URL, phone number, IP address, credit card), Strings and Text (HTML tags, quoted strings, slugs, whitespace), Numbers and Dates (integers, floats, ISO dates, currency), Security (strong passwords, UUID, JWT, Base64), and Programming (variable names, semantic version, import statements).
How do I use regex flags like g, i, and m?
Flags modify matching behaviour. g (global) finds all matches rather than stopping at the first. i (case-insensitive) ignores letter case. m (multiline) makes ^ and $ match the start and end of each line instead of the whole string. s (dotAll) makes the dot match newlines. Flags are appended after the closing slash: /pattern/gim.
What is the difference between greedy and lazy quantifiers?
Greedy quantifiers (*, +, ?) match as much as possible. Lazy quantifiers (*?, +?, ??) match as little as possible. For example, <.*> applied to <b>bold</b> greedily matches the entire string, while <.*?> matches only <b> and then </b> separately. Use lazy quantifiers when extracting tags or quoted strings.
How do I validate an email address with regex?
A production-grade email regex is complex — RFC 5322 allows many unusual formats. A pragmatic pattern that covers the vast majority of real addresses is /^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$/. For critical applications, validate by sending a confirmation email rather than relying solely on regex.
Are these regex patterns compatible with JavaScript, Python, and other languages?
Most patterns use PCRE-compatible syntax that works in JavaScript, Python (re module), PHP, Java, and Go. Some minor differences exist — for example, Python uses (?P<name>) for named groups while JavaScript uses (?<name>). Always test a pattern in your target language before shipping it to production.