BytePane

Regex Pattern Library

Browse 100+ ready-to-use regular expression patterns across 11 categories. Each pattern includes an interactive live tester, code examples, and detailed explanations.

100+
Regex Patterns
11
Categories
44
Beginner Patterns
14
Advanced Patterns

Validation

(8)

Email Address

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

Validates standard email addresses with username, @ symbol, domain, and TLD. Covers most common email formats used in web forms.

Phone Number (US)

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

Matches US phone numbers in common formats including with/without country code, parentheses, dashes, dots, and spaces.

Phone Number (International)

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

Validates international phone numbers following the E.164 standard. Supports 1-15 digits with optional plus prefix.

URL

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

Matches HTTP and HTTPS URLs with optional www prefix, domain, path, query parameters, and fragments.

IPv4 Address

Intermediate
/^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/

Validates IPv4 addresses ensuring each octet is 0-255. Commonly used in network tools, log analysis, and security applications.

IPv6 Address

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

Matches full IPv6 addresses in standard notation with 8 groups of 4 hexadecimal digits separated by colons.

MAC Address

Beginner
/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/

Validates MAC addresses in colon or hyphen-separated format with 6 groups of 2 hexadecimal digits.

Domain Name

Intermediate
/^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/

Validates domain names with proper label formatting, supporting subdomains and various TLD lengths.

#

Numbers

(8)

Date & Time

(10)

Date (YYYY-MM-DD)

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

Validates dates in ISO 8601 format (YYYY-MM-DD) with valid month (01-12) and day (01-31) ranges.

Date (MM/DD/YYYY)

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

Validates dates in US format (MM/DD/YYYY). Ensures month is 01-12 and day is 01-31.

Date (DD/MM/YYYY)

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

Validates dates in day-first format common in Europe and most of the world. Day 01-31, month 01-12.

Time (24-hour)

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

Validates 24-hour time format (HH:MM or HH:MM:SS). Hours 00-23, minutes and seconds 00-59.

Time (12-hour)

Beginner
/^(0?[1-9]|1[0-2]):[0-5]\d\s?[AaPp][Mm]$/

Validates 12-hour time with AM/PM indicator. Hours 1-12, minutes 00-59, with flexible spacing.

ISO 8601 DateTime

Advanced
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})?$/

Validates full ISO 8601 datetime strings with optional milliseconds and timezone offset (Z or +/-HH:MM).

Unix Timestamp

Beginner
/^\d{10,13}$/

Matches Unix timestamps in seconds (10 digits) or milliseconds (13 digits). Used universally in programming.

Relative Date

Intermediate
/^\d+\s+(second|minute|hour|day|week|month|year)s?\s+(ago|from now)$/i

Matches relative time expressions like "5 minutes ago" or "3 months from now" for human-readable timestamps.

Duration (HH:MM:SS)

Beginner
/^\d+:[0-5]\d:[0-5]\d$/

Validates time duration format with hours (any count), minutes (00-59), and seconds (00-59).

Cron Expression

Advanced
/^(\*|\d+|\d+-\d+|\d+\/\d+)(\s+(\*|\d+|\d+-\d+|\d+\/\d+)){4}$/

Validates standard 5-field cron expressions (minute, hour, day, month, weekday) with wildcards and ranges.

T

Text & Strings

(12)

Username

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

Validates usernames with letters, numbers, underscores, and hyphens. Length 3-20 characters.

Strong Password

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

Enforces strong password policy: minimum 8 characters with at least one uppercase, lowercase, digit, and special character.

Slug (URL-friendly)

Beginner
/^[a-z0-9]+(-[a-z0-9]+)*$/

Validates URL-friendly slugs with lowercase letters, numbers, and hyphens. No consecutive or trailing hyphens.

Hashtag

Beginner
/#[a-zA-Z][a-zA-Z0-9_]*/g

Extracts hashtags starting with # followed by a letter and optional alphanumeric/underscore characters.

HTML Tag

Intermediate
/<\/?[a-zA-Z][a-zA-Z0-9]*\b[^>]*>/g

Matches opening and closing HTML tags with optional attributes. Useful for HTML manipulation and content extraction.

HTML Comments

Beginner
/<!--[\s\S]*?-->/g

Matches HTML comments including multi-line content. Used for stripping comments during minification or processing.

Quoted String

Advanced
/(["'])(?:(?!\1|\\).|\\.)*\1/g

Matches single or double-quoted strings with proper escape handling. Handles escaped quotes within strings.

Markdown Link

Intermediate
/\[([^\]]+)\]\(([^)]+)\)/g

Matches Markdown inline links capturing both the display text and URL. Essential for Markdown-to-HTML converters.

Markdown Heading

Beginner
/^(#{1,6})\s+(.+)$/gm

Matches Markdown headings H1-H6. Captures the level (number of #) and heading text.

Whitespace Trimmer

Beginner
/^\s+|\s+$/gm

Matches leading and trailing whitespace for trimming. Equivalent to the trim() method in most languages.

Duplicate Words

Intermediate
/\b(\w+)\s+\1\b/gi

Detects consecutively repeated words like "the the" or "is is". Useful for proofreading and text cleanup.

Sentence

Beginner
/[A-Z][^.!?]*[.!?]/g

Matches sentences starting with a capital letter and ending with period, exclamation, or question mark.

</>

Code & Programming

(12)

JavaScript Variable

Intermediate
/\b(const|let|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g

Matches JavaScript variable declarations (const, let, var) and captures the variable name.

JavaScript Function

Intermediate
/\bfunction\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\(/g

Matches named function declarations in JavaScript, capturing the function name.

CSS Hex Color

Beginner
/#([0-9a-fA-F]{3}){1,2}\b/g

Matches 3 or 6-digit hex color codes. Commonly used to extract or validate colors from CSS stylesheets.

CSS Class Selector

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

Matches CSS class selectors starting with a dot. Captures class names from stylesheets for analysis.

Python Import

Intermediate
/^(?:from\s+[\w.]+\s+)?import\s+[\w.,\s]+$/gm

Matches Python import statements including `import` and `from...import` forms for dependency tracking.

SQL SELECT Statement

Intermediate
/\bSELECT\b[\s\S]+?\bFROM\b\s+\w+/gi

Matches SQL SELECT queries extracting the table name from the FROM clause. Useful for query analysis and logging.

JSON Key-Value Pair

Intermediate
/"([^"]+)"\s*:\s*("([^"]*)"|\d+|true|false|null)/g

Matches JSON key-value pairs with string, number, boolean, or null values. Useful for lightweight JSON processing.

TODO Comment

Beginner
/\/\/\s*(TODO|FIXME|HACK|XXX|BUG):\s*(.+)$/gm

Extracts TODO, FIXME, HACK, XXX, and BUG comments from source code for task tracking.

Semantic Version

Intermediate
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-[a-zA-Z0-9.]+)?(\+[a-zA-Z0-9.]+)?$/

Validates semantic version strings (SemVer) with major.minor.patch and optional pre-release and build metadata.

Git Commit Hash

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

Matches Git commit SHA hashes in both short (7 chars) and full (40 chars) formats.

Environment Variable

Beginner
/^[A-Z][A-Z0-9_]*=.+$/gm

Matches environment variable assignments in KEY=VALUE format with uppercase keys and underscores.

Import Path

Intermediate
/['"]([./]\S+?)['"]/g

Extracts relative import paths from JavaScript/TypeScript import and require statements.

🔐

Security & Auth

(8)
{}

Data Formats

(10)

JSON Object

Beginner
/\{[\s\S]*\}/

Matches JSON object patterns enclosed in curly braces. Simple detection pattern for JSON objects in text.

CSV Row

Advanced
/^("(?:[^"]|"")*"|[^,]*)(,("(?:[^"]|"")*"|[^,]*))*$/gm

Matches CSV rows handling quoted fields with escaped quotes. Essential for robust CSV file processing.

XML Tag with Content

Intermediate
/<(\w+)[^>]*>(.*?)<\/\1>/gs

Matches XML elements with opening tag, content, and matching closing tag. Captures tag name and inner content.

YAML Key-Value

Beginner
/^([\w.-]+):\s+(.+)$/gm

Matches simple YAML key-value pairs. Useful for quick parsing of configuration files.

Log Entry (Common Log Format)

Advanced
/^(\S+)\s+(\S+)\s+(\S+)\s+\[([^\]]+)\]\s+"(\S+)\s+(\S+)\s+(\S+)"\s+(\d+)\s+(\d+)/gm

Parses Apache/Nginx Common Log Format entries, extracting IP, timestamp, method, path, status code, and bytes.

INI Section

Beginner
/^\[([^\]]+)\]$/gm

Matches INI file section headers enclosed in square brackets. Used for parsing configuration files.

TOML Key-Value

Beginner
/^([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*(.+)$/gm

Matches TOML configuration key-value pairs. Standard format for Rust (Cargo) and Python (pyproject) projects.

SQL Comment

Intermediate
/--.*$|\/\*[\s\S]*?\*\//gm

Matches both single-line (--) and multi-line (/* */) SQL comments for stripping or extracting documentation.

Docker Image Reference

Intermediate
/^([a-z0-9._-]+\/)?[a-z0-9._-]+(:[a-zA-Z0-9._-]+)?(@sha256:[a-f0-9]{64})?$/

Validates Docker image references with optional registry, tag, and digest. Used in Dockerfiles and compose files.

File Path (Unix)

Beginner
/^\/(?:[a-zA-Z0-9._-]+\/?)*$/

Matches absolute Unix/Linux file paths starting with forward slash. Validates path component characters.

🌐

Web & HTML

(10)

Email in Text

Beginner
/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g

Extracts email addresses from body text. Non-anchored version for finding emails within larger strings.

Image Tag (src)

Intermediate
/<img[^>]+src=["']([^"']+)["']/gi

Extracts image source URLs from HTML img tags. Useful for web scraping, SEO image audits, and content migration.

Anchor Tag (href)

Intermediate
/<a[^>]+href=["']([^"']+)["']/gi

Extracts URLs from HTML anchor tags. Essential for web crawlers, SEO tools, and broken link checkers.

Meta Tag Content

Intermediate
/<meta[^>]+content=["']([^"']+)["']/gi

Extracts content attribute values from HTML meta tags for SEO auditing and metadata analysis.

Inline CSS Style

Beginner
/style=["']([^"']+)["']/gi

Matches inline CSS style attributes on HTML elements. Used for style extraction and converting inline styles to classes.

YouTube Video ID

Intermediate
/(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/)([a-zA-Z0-9_-]{11})/g

Extracts 11-character YouTube video IDs from various URL formats including standard, shortened, and embed URLs.

Twitter/X Handle

Beginner
/@([a-zA-Z0-9_]{1,15})\b/g

Matches Twitter/X handles with @ prefix and 1-15 alphanumeric characters or underscores.

GitHub Repository URL

Beginner
/github\.com\/([a-zA-Z0-9_.-]+)\/([a-zA-Z0-9_.-]+)/g

Extracts owner and repository name from GitHub URLs. Used in dependency management and open source tooling.

CSS Media Query

Intermediate
/@media\s*\([^)]+\)\s*\{/g

Matches CSS media query declarations for responsive design. Extracts breakpoints and conditions from stylesheets.

Data Attribute

Beginner
/data-([a-z-]+)=["']([^"']*)["']/gi

Matches HTML5 data attributes (data-*) and captures both the attribute name and value.

📁

File & Path

(6)
🪪

Identity & Documents

(8)

Advanced Patterns

(8)

What Are Regular Expressions?

Regular expressions (regex) are sequences of characters that define search patterns. They are used across virtually all programming languages for string matching, validation, search-and-replace, and data extraction. From validating email addresses to parsing log files, regex is an essential tool in every developer's toolkit.

Each pattern in our library includes an interactive live tester where you can paste your own text and see matches in real-time. We also provide code examples in JavaScript, Python, and Go so you can copy-paste directly into your project.

Related Developer Tools