Regex Pattern Library
A curated collection of regular expressions for everyday development tasks. Copy, paste, and understand exactly how these patterns validate and extract data.
Dates & Numbers
ISO 8601 Date Validation
Validates dates in ISO 8601 format (YYYY-MM-DD).
24-Hour Time Validation
Validates time in 24-hour format (HH:MM or HH:MM:SS).
Currency Amount Validation
Validates US currency amounts like $1,234.56 or 1234.56.
ISO 8601 Datetime with UTC Z
Matches an ISO 8601 datetime in UTC (Z suffix).
Unix Timestamp (Seconds)
Matches a 10-digit Unix timestamp in seconds (the 2001–2286 range).
Unix Timestamp (Milliseconds)
Matches a 13-digit Unix timestamp in milliseconds.
ISO 8601 Duration
Matches an ISO 8601 duration (PT1H30M, P3D, P1Y2M3DT4H5M6S).
Scientific Notation Number
Matches a numeric literal in optional scientific notation (1e9, 3.14e-2).
Binary Number (0b prefix)
Matches a binary literal in the 0b... form (JS, Python, Rust).
Hexadecimal Number (0x prefix)
Matches a 0x-prefixed hex literal.
Extraction
URL Extraction
Extract URLs starting with http or https from a larger block of text.
Markdown Link Extraction
Extracts Markdown inline links, capturing both the link text and the URL.
HTML Tag Extraction
Extracts opening HTML tags and their tag names from an HTML string.
HTML Comment Extraction
Extracts HTML comments from an HTML string.
HTML Heading Tag Extraction
Extracts HTML heading tags (h1-h6) and their text content.
YouTube Video ID
Validates an 11-character YouTube video ID.
YouTube URL, Extract Video ID
Extracts the 11-char video ID from any common YouTube URL shape.
JSON String Literal
Matches a single JSON-encoded string literal per RFC 8259.
ANSI Escape Sequence (Terminal Control)
Matches an ANSI escape sequence (e.g., color codes, cursor movement).
File & Path
Windows File Path Validation
Validates Windows absolute file paths like C:\Users\name\file.txt.
Unix/Linux File Path Validation
Validates Unix absolute file paths like /usr/local/bin/node.
Windows Drive Letter Path
Matches the prefix of a Windows drive-letter absolute path (C:\... or C:/...).
Security
Strong Password Validation
Validates a strong password (min 8 chars, 1 uppercase, 1 lowercase, 1 number, 1 special char).
Credit Card Number Validation
Validates Visa, Mastercard, American Express, and Discover card numbers (digits only, no spaces).
JWT Format Validation
Validates that a string has the three-part Base64URL structure of a JSON Web Token.
Generic API Key Format Validation
Validates generic API keys: 20-64 alphanumeric characters with underscores and hyphens.
Password Without Spaces
Validates that a password is at least 8 characters with no spaces.
Stripe Secret API Key
Detects a Stripe secret API key. Useful for secret-scanning hooks.
JWT Three-Segment Structure
Validates the three-segment base64url shape of a JWT, header.payload.signature.
Redacted Token Marker
Matches common log-redaction markers used to scrub secrets.
Validation
Email Address Validation
A standard regex pattern to validate most common email address formats.
Hexadecimal Color Validation
Validates 3-digit and 6-digit hex color codes.
Phone Number (E.164 International)
Validates international phone numbers in E.164 format (e.g. +14155552671).
US Phone Number Validation
Validates US phone numbers in common formats including (555) 555-5555, 555-555-5555, and +1 555 555 5555.
UUID v4 Validation
Validates a UUID version 4 (randomly generated) in standard hyphenated format.
Semantic Version (SemVer) Validation
Validates semantic version strings like 1.2.3, 1.0.0-alpha.1, and 2.0.0+build.123.
US Social Security Number (SSN)
Validates US Social Security Numbers in the standard XXX-XX-XXXX format.
US ZIP Code Validation
Validates US ZIP codes in 5-digit (12345) and ZIP+4 (12345-6789) formats.
Base64 String Validation
Validates standard Base64-encoded strings including padding.
Docker Image Tag Validation
Validates Docker image references like nginx:latest, myrepo/myimage:1.0.0, or registry.example.com/org/image:tag.
Environment Variable Name Validation
Validates POSIX-compliant environment variable names: uppercase letters, digits, and underscores, not starting with a digit.
Git Commit Hash Validation
Validates Git commit hashes in short (7-char) or full (40-char) SHA-1 format.
Username Validation
Validates usernames: 3–20 characters, letters, numbers, underscores, and hyphens only.
Twitter/X Handle Validation
Validates Twitter/X handles with optional @ prefix, 1-15 alphanumeric characters and underscores.
CSS Class Name Validation
Validates CSS class names per the CSS specification.
AWS S3 Bucket Name Validation
Validates AWS S3 bucket names per AWS naming rules.
npm Package Name Validation
Validates npm package names including scoped packages like @org/package.
SQL Identifier Validation
Validates SQL identifiers (table names, column names): letters, digits, and underscores, not starting with a digit.
CSS RGB Color Validation
Validates CSS rgb() color values like rgb(255, 128, 0).
Git Branch Name Validation
Validates Git branch names per git check-ref-format rules.
MIME Type Validation
Validates MIME type strings like text/html, application/json, image/png.
CSS HSL Color Validation
Validates CSS hsl() color values like hsl(120, 100%, 50%).
Latitude/Longitude Coordinate Validation
Validates a latitude,longitude coordinate pair like 37.7749,-122.4194.
ISBN-13 Validation
Validates ISBN-13 book identifiers starting with 978 or 979.
Docker Container Name Validation
Validates Docker container names: alphanumeric, underscores, dots, and hyphens.
YAML Key Validation
Validates simple YAML keys: letters, digits, underscores, and hyphens, starting with a letter or underscore.
UK Phone Number Validation
Validates UK mobile phone numbers in +447xxxxxxxxx or 07xxxxxxxxx format.
Indian Phone Number Validation
Validates Indian mobile phone numbers with optional +91 or 0 prefix.
Stripe Customer ID
Validates a Stripe Customer ID (cus_XXXXXXXXXXXXXX).
Stripe Charge ID
Validates a Stripe Charge ID (ch_XXXXXXXX...).
Stripe Payment Intent ID
Validates a Stripe Payment Intent ID (pi_XXXXXXXX...).
GitHub Username
Validates a GitHub username per GitHub's documented rules.
GitHub owner/repo Path
Matches a GitHub owner/repository path like 'torvalds/linux'.
Git Short SHA (7 hex)
Matches a 7-character abbreviated Git commit SHA.
MongoDB ObjectId
Validates a MongoDB ObjectId, 24 hex characters.
ULID Identifier
Validates a ULID (Universally Unique Lexicographically Sortable Identifier).
NanoID
Validates a default 21-character NanoID.
Bitcoin Address (P2PKH, P2SH, Bech32)
Matches legacy (1...), P2SH (3...), and Bech32 (bc1...) Bitcoin addresses.
Ethereum Address
Validates a hex-encoded Ethereum address (40 hex chars, 0x-prefixed).
Vimeo Video ID
Validates a Vimeo video ID, 6–12 digits.
UK Postal Code
Validates a UK postal code (postcode) with optional space.
Canadian Postal Code
Validates a Canadian postal code (A1A 1A1).
India Pincode
Validates an Indian 6-digit PIN code.
ISO 3166-1 alpha-2 Country Code
Matches a 2-letter uppercase ISO country code (US, GB, IN, ...).
ISO 4217 Currency Code
Matches a 3-letter uppercase ISO currency code (USD, EUR, GBP, ...).
ISO 639-1 Language Code
Matches a 2-letter language code with optional region (en, en-US, pt-BR).
JSON Pointer (RFC 6901)
Validates a JSON Pointer string per RFC 6901.
Python Identifier
Matches a Python identifier (ASCII; PEP 8 ASCII recommendation).
Go Module Path
Matches a Go module import path (e.g., github.com/anthropics/claude-code).
Rust Crate Name
Validates a Rust crate name as accepted by crates.io.
Java Package Name
Validates a Java package name (lowercase segments separated by dots).
Tracking ID (UUID v4 or ULID)
Matches either a UUID v4 or a ULID, common identifiers in distributed tracing.
Web & Network
IPv4 Address Validation
Validates a standard dotted-decimal IPv4 address.
IPv6 Address Validation
Validates a full (non-compressed) IPv6 address in colon-hexadecimal notation.
URL Slug Validation
Validates a URL-safe slug: lowercase letters, numbers, and hyphens only, no leading/trailing hyphens.
CIDR Notation Validation
Validates IPv4 CIDR notation like 192.168.1.0/24.
MAC Address Validation
Validates MAC addresses in colon-separated (AA:BB:CC:DD:EE:FF) or hyphen-separated (AA-BB-CC-DD-EE-FF) formats.
Data URI Validation
Validates data URIs like data:image/png;base64, or data:text/plain,.
Network Port Number Validation
Validates TCP/UDP port numbers in the valid range 1-65535.
Stripe Publishable API Key
Matches a Stripe publishable key (safe to expose in client-side code).
AWS ARN
Matches the structure of an AWS Amazon Resource Name (ARN).
AWS Account ID
Validates a 12-digit AWS account ID.
Hex Color With Optional Alpha (#RGB / #RGBA / #RRGGBB / #RRGGBBAA)
Matches modern CSS hex colors including 3, 4, 6, or 8 hex digits (alpha-channel forms).
CSS rgba() Color
Validates a CSS rgba(r, g, b, a) color string.
CSS hsla() Color
Validates a CSS hsla(h, s, l, a) color string.
Data URL (data:)
Matches a data: URL with MIME type, optional parameters, optional base64 flag, and payload.
IPv4 CIDR Block
Validates an IPv4 address with a /0–/32 CIDR suffix.
IPv6 CIDR Block
Matches an IPv6 address (loosely) with a /0–/128 mask.
Kubernetes Resource Name (DNS subdomain)
Validates a Kubernetes resource name following the RFC 1123 DNS subdomain rules.
Kubernetes Label Value
Validates a Kubernetes label value, up to 63 chars, alphanumeric/dot/underscore/hyphen.
URI Scheme Prefix
Matches the scheme part of a URI per RFC 3986.
Open Graph Image URL
Matches a remote image URL suitable for Open Graph meta tags.