DD
DevDash

Regex Pattern Library

201 tested regex patterns for email, phone, URL, password, UUID, date, credit card, and more. Each page has copy-paste code for JavaScript, Python, Ruby, PHP, and Java.

Quick Answer

Regex (regular expressions) define patterns for matching text. Common uses: validating email, phone numbers, URLs, passwords; extracting data; find-and-replace. Most languages use PCRE-compatible syntax with minor differences in flags and escaping. Click any pattern below for tested examples and copy-paste code in 5 languages.

Common Validation

Phone Numbers

Passwords

Networking

Payment

Identifiers

UUID v4

UUID version 4 (randomly generated)

^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[8...

UUID (Any Version)

Any RFC 4122 UUID (versions 1-5)

^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3...

JWT Token

JSON Web Token (header.payload.signature)

^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z...

Hex String

Any-length hexadecimal string

^[0-9a-fA-F]+$

Base64 String

Standard base64 encoded string

^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2...

Alphanumeric Username

Username with letters, digits, underscores (3-16 chars)

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

Twitter Handle

Twitter/X handle, 1-15 chars, optional @

^@?(\w){1,15}$

URL Slug

Lowercase URL-friendly slug with dashes

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

US Social Security Number

US SSN format (XXX-XX-XXXX) with basic validity checks

^(?!000|666|9\d{2})\d{3}-(?!00)\d{2}-(?!...

US EIN (Employer ID)

US Employer Identification Number (XX-XXXXXXX)

^\d{2}-\d{7}$

EU VAT Number

EU VAT identification number (country code + digits)

^[A-Z]{2}\d{2,12}$

Indian PAN Number

Indian Permanent Account Number (AAAAA1234A)

^[A-Z]{5}\d{4}[A-Z]$

Git Commit Hash

Git commit SHA hash (7-40 hex characters)

^[0-9a-f]{7,40}$

Git Branch Name

Valid git branch name following git-check-ref-format rules

^(?!.*\.\.)(?!.*\/\/)(?!\/)[a-zA-Z0-9/_....

Strict URL Slug

Strict slug: starts with letter, lowercase alphanumeric with dashes

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

Social Handle (@)

Social media handle with @ prefix (1-30 chars)

^@[a-zA-Z0-9_]{1,30}$

AWS ARN

Amazon Web Services ARN (Amazon Resource Name)

^arn:aws[a-zA-Z-]*:[a-zA-Z0-9-]+:[a-z]{2...

AWS S3 Bucket Name

Valid AWS S3 bucket name (3-63 chars, lowercase)

^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$

AWS Region

AWS region identifier (e.g. us-east-1)

^[a-z]{2}-[a-z]+-\d$

AWS Account ID

AWS account ID — exactly 12 digits

^\d{12}$

Google Analytics ID

Google Analytics tracking ID (UA or GA4)

^(?:UA-\d{4,10}-\d{1,4}|G-[A-Z0-9]{10,})...

Google Tag Manager ID

Google Tag Manager container ID

^GTM-[A-Z0-9]{6,8}$

Stripe API Key

Stripe publishable, secret, or restricted key format

^(?:pk|sk|rk)_(?:test|live)_[a-zA-Z0-9]{...

ISBN-10

ISBN-10 — 9 digits plus a check digit (0-9 or X)

^\d{9}[\dX]$

ISBN-13

ISBN-13 — starts with 978 or 979, 13 digits total

^97[89]\d{10}$

DOI Number

Digital Object Identifier (DOI) starting with 10.

^10\.\d{4,9}\/[-._;()/:a-zA-Z0-9]+$

VIN (Vehicle ID)

Vehicle Identification Number — 17 alphanumeric chars (no I, O, Q)

^[A-HJ-NPR-Z0-9]{17}$

TOTP Secret (Base32)

Base32-encoded TOTP secret key (16+ uppercase letters and 2-7)

^[A-Z2-7]{16,}$

JWT Token (Strict)

Strict JWT starting with eyJ (base64 encoded JSON header and payload)

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

Bearer Auth Header

HTTP Bearer Authorization header value

^Bearer\s+[A-Za-z0-9._~+/=-]+$

Basic Auth Header

HTTP Basic Authorization header (base64 encoded credentials)

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

Base64 String (Strict)

Strict base64 encoded string (min 4 chars, proper padding)

^[A-Za-z0-9+/]{4,}(?:={0,2})$

CVE Identifier

Common Vulnerabilities and Exposures (CVE) ID

^CVE-\d{4}-\d{4,}$

Generic API Key

Generic API key format (20+ alphanumeric, underscore, or dash characters)

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

US License Plate

US license plate — 1-8 uppercase alphanumeric characters

^[A-Z0-9]{1,8}$

Slack Channel Name

Valid Slack channel name (lowercase, max 80 chars)

^[a-z0-9][a-z0-9_-]{0,79}$

Discord Username

Discord username (2-32 chars, lowercase alphanumeric with dots and underscores)

^[a-z0-9_.]{2,32}$

Date & Time

Postal Codes

Numbers

File Paths

HTML & Markup

Whitespace

Web & Network

Subdomain Extraction

Extracts the subdomain from a URL or domain name

^(?:https?:\/\/)?([a-zA-Z0-9](?:[a-zA-Z0...

Protocol Detection

Detects and captures the protocol from a URL

^([a-zA-Z][a-zA-Z0-9+.-]*):\/\/

Port Number

Extracts port number from a URL or host string

:([0-9]{1,5})(?:\/|$)

Query Parameter

Extracts key-value pairs from URL query strings

[?&]([a-zA-Z0-9_]+)=([^&#]*)

HTTP vs HTTPS URL

Matches HTTP or HTTPS URLs and captures the protocol

^(https?):\/\/[^\s]+$

Data URL

Matches data: URL scheme with optional MIME type and base64 encoding

^data:([a-zA-Z]+\/[a-zA-Z0-9.+-]+)?(;bas...

WebSocket URL

WebSocket URL starting with ws:// or wss://

^wss?:\/\/[^\s/$.?#].[^\s]*$

FTP URL

FTP or FTPS URL

^ftps?:\/\/[^\s/$.?#].[^\s]*$

SSH URL

SSH connection string (ssh:// or user@host format)

^(?:ssh:\/\/)?(?:[a-zA-Z0-9._-]+@)?[a-zA...

Git URL

Git repository URL (HTTPS, SSH, or git:// protocol)

^(?:git|https?|ssh):\/\/[^\s]+\.git$|^[a...

MIME Type

Standard MIME type format (type/subtype)

^[a-zA-Z]+\/[a-zA-Z0-9.+-]+$

Content-Type Header

HTTP Content-Type header with optional parameters

^[a-zA-Z]+\/[a-zA-Z0-9.+-]+(?:\s*;\s*[a-...

Browser User Agent

Detects browser-style User-Agent strings starting with Mozilla/5.0

Mozilla\/5\.0\s+\([^)]+\)

Bot User Agent

Detects common bot/crawler User-Agent keywords

(?:bot|crawl|spider|slurp|fetch|archiv)(...

GitHub Repository URL

GitHub repository URL

^https:\/\/github\.com\/[a-zA-Z0-9._-]+\...

X-Forwarded-For Header

X-Forwarded-For header with comma-separated IPs

^(?:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(?...

CORS Origin

CORS Access-Control-Allow-Origin value (* or origin URL)

^(?:\*|https?:\/\/[a-zA-Z0-9.-]+(?::\d+)...

Relative URL

Relative URL path starting with /

^\/[^\s]*$

Absolute URL

Absolute URL with any protocol scheme

^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^\s]+$

Code

JavaScript Variable Name

Valid JavaScript variable/identifier name

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

Python Variable Name

Valid Python identifier name

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

CSS Class Name

Valid CSS class name (starts with letter, underscore, or hyphen)

^-?[_a-zA-Z][_a-zA-Z0-9-]*$

CSS ID Selector

CSS ID selector starting with #

^#[_a-zA-Z][_a-zA-Z0-9-]*$

JSON Key

JSON object key (quoted string followed by colon)

"([^"\\]*(?:\\.[^"\\]*)*)"\s*:

Semantic Version (Strict)

Strict semantic versioning (MAJOR.MINOR.PATCH)

^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*...

SemVer with Pre-release

Full semantic version with optional pre-release and build metadata

^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*...

JavaScript Import Statement

ES module import statement in JavaScript/TypeScript

^import\s+(?:\{[^}]*\}|[a-zA-Z_$][\w$]*)...

JavaScript Require Statement

CommonJS require statement in Node.js

(?:const|let|var)\s+(?:\{[^}]*\}|[a-zA-Z...

Python Import Statement

Python import or from...import statement

^(?:from\s+[a-zA-Z_][a-zA-Z0-9_.]*\s+)?i...

SQL SELECT Statement

Basic SQL SELECT...FROM statement

^\s*SELECT\s+.+\s+FROM\s+\w+

Docker Image Tag

Docker image name with optional registry and tag

^(?:[a-z0-9]+(?:[._-][a-z0-9]+)*\/)*[a-z...

npm Package Name

Valid npm package name (scoped or unscoped)

^(?:@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-...

Cron Expression (5-field)

Standard 5-field cron expression (min hour dom month dow)

^(?:[0-9*,/-]+\s+){4}[0-9*,/-]+$

Cron Expression (6-field Quartz)

6-field Quartz/Spring cron expression with seconds

^(?:[0-9*,/-]+\s+){5}[0-9*,/?L#-]+$

Environment Variable Name

Standard environment variable name (uppercase with underscores)

^[A-Z_][A-Z0-9_]*$

Dotenv Line

.env file line (KEY=value format)

^[A-Z_][A-Z0-9_]*=.*$

Dockerfile Instruction

Dockerfile instruction keyword at start of line

^(?:FROM|RUN|CMD|LABEL|MAINTAINER|EXPOSE...

Kubernetes Label

Kubernetes label key with optional prefix (prefix/name)

^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-z...

Docker Container ID

Docker container ID (short 12 or full 64 hex chars)

^[0-9a-f]{12}(?:[0-9a-f]{52})?$

SemVer Range (npm-style)

npm-style version range with optional ~ or ^ prefix

^[~^]?(0|[1-9]\d*)(?:\.(0|[1-9]\d*)(?:\....

package.json Script

package.json script entry ("name": "command")

"([a-zA-Z0-9:_-]+)"\s*:\s*"([^"]*)"

Makefile Target

Makefile target definition (name followed by colon)

^[a-zA-Z0-9_.-]+\s*:(?!=)

JSON Boolean

JSON boolean literal (true or false)

^(?:true|false)$

JSON Null

JSON null literal

^null$

Git Version Tag

Git version tag with optional v prefix (v1.0.0 or 1.0.0)

^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\...

Text Processing

Security

Want API access + no ads? Pro coming soon.