Developer Tools

Regex Library

Browse and copy common regular expressions for validation, extraction, and text processing

45 patterns

Email Address

Validation

Matches a standard email address format

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

URL

Validation

Matches http and https URLs with optional paths and query strings

/https?:\/\/(www\.)?[-\w@:%._+~#=]{1,256}\.[a-zA-Z]{2,6}\b([-\w@:%_+.~#?&\/=]*)/
Example: https://example.com/path?q=1

IPv4 Address

Validation

Matches a valid IPv4 address (0–255 per octet)

/^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/
Example: 192.168.1.1

IPv6 Address

Validation

Matches a full-form IPv6 address

/^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/
Example: 2001:0db8:85a3:0000:0000:8a2e:0370:7334

Phone Number

Validation

Matches international and US phone numbers (loose format)

/^\+?[\d\s\-().]{7,15}$/
Example: +1 (555) 123-4567

US ZIP Code

Validation

Matches 5-digit and ZIP+4 US postal codes

/^\d{5}(-\d{4})?$/
Example: 90210 or 90210-1234

Strong Password

Validation

Requires uppercase, lowercase, digit, special char, min 8 chars

/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_]).{8,}$/
Example: P@ssw0rd!

UUID / GUID

Validation

Matches RFC 4122 UUID format

/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
Example: 550e8400-e29b-41d4-a716-446655440000

Credit Card Number

Validation

Matches Visa, Mastercard, Amex, and Discover card numbers

/^(?:4\d{12}(?:\d{3})?|5[1-5]\d{14}|3[47]\d{13}|6(?:011|5\d{2})\d{12})$/
Example: 4111111111111111

Social Security Number

Validation

Matches US SSN format, excluding known invalid prefixes

/^(?!000|666|9\d{2})\d{3}-(?!00)\d{2}-(?!0000)\d{4}$/
Example: 123-45-6789

Slug

Validation

Matches URL-safe slugs (lowercase, hyphens, no leading/trailing hyphens)

/^[a-z0-9]+(?:-[a-z0-9]+)*$/
Example: my-blog-post-title

Username

Validation

Starts with a letter, 3–20 chars, allows letters, digits, underscores

/^[a-zA-Z][a-zA-Z0-9_]{2,19}$/
Example: john_doe42

Date (YYYY-MM-DD)

Extraction

Extracts ISO 8601 dates

/\b\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])\b/
Example: 2024-03-15

Date (MM/DD/YYYY)

Extraction

Extracts US-format dates with capture groups for month, day, year

/\b(0?[1-9]|1[0-2])\/(0?[1-9]|[12]\d|3[01])\/(\d{4})\b/
Example: 03/15/2024

Time (HH:MM)

Extraction

Extracts 24-hour clock times

/\b([01]\d|2[0-3]):[0-5]\d\b/
Example: 14:30

Time (HH:MM:SS)

Extraction

Extracts 24-hour times with seconds

/\b([01]\d|2[0-3]):[0-5]\d:[0-5]\d\b/
Example: 14:30:59

Hex Color

Extraction

Extracts 3- or 6-digit hex color codes

/#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})\b/
Example: #ff6600 or #f60

Integer

Extraction

Matches positive or negative integers

/^-?\d+$/
Example: -42 or 1000

Decimal Number

Extraction

Matches integers and floating-point numbers

/^-?\d+(\.\d+)?$/
Example: 3.14 or -2.5

Scientific Notation

Extraction

Extracts numbers in scientific notation

/-?\d+(\.\d+)?([eE][+-]?\d+)?/
Example: 6.022e23 or 1.5E-10

Currency (USD)

Extraction

Extracts US dollar amounts with optional cents

/\$\d{1,3}(,\d{3})*(\.\d{2})?/
Example: $1,234.56

Twitter / X Handle

Extraction

Extracts @mention handles

/@[a-zA-Z0-9_]{1,15}/
Example: @johndoe

Hashtag

Extraction

Extracts hashtags starting with a letter

/#[a-zA-Z][\w]*/
Example: #javascript

Trim Whitespace

Text Processing

Matches leading and trailing whitespace for removal

/^\s+|\s+$/g
Example: hello world

Collapse Multiple Spaces

Text Processing

Matches two or more consecutive whitespace characters

/\s{2,}/g
Example: hello world

Empty Lines

Text Processing

Matches blank or whitespace-only lines

/^\s*$/gm
Example: line1 line2

Repeated Words

Text Processing

Finds accidentally duplicated consecutive words

/\b(\w+)\s+\1\b/gi
Example: the the quick brown fox

HTML Tags

Text Processing

Matches HTML element open/close pairs with content

/<([a-z][a-z0-9]*)([^>]*)>(.*?)<\/\1>/gis
Example: <p class="foo">Hello</p>

HTML Comments

Text Processing

Matches HTML comment blocks

/<!--[\s\S]*?-->/g
Example: <!-- This is a comment -->

Single-Line Comment (//)

Text Processing

Matches C-style single-line comments

/\/\/.*$/gm
Example: const x = 1; // a comment

Single-Line Comment (#)

Text Processing

Matches shell/Python-style single-line comments

/#.*$/gm
Example: x = 1 # a comment

Multi-Line Comment (/* */)

Text Processing

Matches C-style block comments

/\/\*[\s\S]*?\*\//g
Example: /* multi line */

Semantic Version

Code & Dev

Matches semver strings like 1.2.3, 1.0.0-beta.1

/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-[a-zA-Z0-9.]+)?(\+[a-zA-Z0-9.]+)?$/
Example: 2.1.0-alpha.1+build.42

File Extension

Code & Dev

Extracts file extension from a filename or path

/\.([a-zA-Z0-9]+)$/
Example: image.png β†’ png

Environment Variable Name

Code & Dev

Matches POSIX-style environment variable names

/^[A-Z][A-Z0-9_]*$/
Example: DATABASE_URL

SQL Identifier

Code & Dev

Matches valid SQL table and column names

/^[a-zA-Z_][a-zA-Z0-9_]*$/
Example: user_id

CSS Class Selector

Code & Dev

Extracts CSS class selectors from a stylesheet

/\.[a-zA-Z][a-zA-Z0-9-_]*/g
Example: .my-button

CSS ID Selector

Code & Dev

Extracts CSS ID selectors from a stylesheet

/#[a-zA-Z][a-zA-Z0-9-_]*/g
Example: #main-content

Camel to Snake Case

Code & Dev

Finds camelCase boundaries. Replace with $1_$2 and lowercase.

/([a-z])([A-Z])/g
Example: camelCaseString β†’ camel_case_string

JWT Token

Security

Matches a 3-part Base64URL-encoded JWT

/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
Example: eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyIn0.abc123

Base64 String

Security

Matches a standard Base64-encoded string

/^[A-Za-z0-9+\/]+=*$/
Example: SGVsbG8gV29ybGQ=

MAC Address

Security

Matches colon- or hyphen-separated MAC addresses

/^([0-9A-Fa-f]{2}[:\-]){5}([0-9A-Fa-f]{2})$/
Example: AA:BB:CC:DD:EE:FF

CIDR Block

Security

Matches IPv4 CIDR notation

/^(\d{1,3}\.){3}\d{1,3}\/([0-9]|[1-2]\d|3[0-2])$/
Example: 192.168.0.0/24

AWS Access Key ID

Security

Detects leaked AWS Access Key IDs in text or code

/\bAKIA[0-9A-Z]{16}\b/
Example: AKIAIOSFODNN7EXAMPLE

PEM Header

Security

Matches PEM-encoded certificate or key headers

/-----BEGIN [\w ]+-----/
Example: -----BEGIN CERTIFICATE-----