Common Regex Patterns
A comprehensive reference of 50+ regular expression patterns for validation, extraction, and text manipulation — organized by category with live testing links to the interactive Regex Tester. Every pattern includes what it matches and a real-world use case so you can copy, understand, and apply it immediately.
What Are Regex Patterns?
Regular expressions (regex) are sequences of characters that define a search pattern — a mini-language for matching, extracting, and manipulating text. Every developer encounters regex for tasks like validating user input, parsing log files, transforming data formats, and extracting information from unstructured text.
This reference covers the most frequently used regex patterns organized into three categories: validation patterns that check whether input conforms to a format (email, URL, phone, date, UUID), extraction patterns that pull specific elements from text (HTML tags, URLs, numbers, quoted strings), and replacement patterns that transform text (whitespace cleanup, case conversion, number formatting).
Click “Test this pattern” on any pattern below to open it pre-filled in the LangStop Regex Tester — a live, interactive environment where you can experiment with each pattern against your own sample text, toggle flags, inspect capture groups, and even test replacement operations.
Validation Patterns
Patterns for verifying that input matches a specific format — essential for form validation, data integrity, and API input sanitization.
Email Address
^[\w\.-]+@[\w\.-]+\.\w{2,}$Matches: Validates a standard email address with username, domain, and TLD.
Use case: Form validation for user registration, contact forms, and newsletter signups.
Test this pattern →URL
https?:\/\/[\w\-\.]+\.\w{2,}\/?\S*Matches: Matches HTTP or HTTPS URLs with domain, optional path, and query string.
Use case: Link validation, URL extraction from text, and click tracking.
Test this pattern →IPv4 Address
\b(?:\d{1,3}\.){3}\d{1,3}\bMatches: Matches a basic IPv4 address — four octets separated by dots.
Use case: Network configuration validation, log analysis, and IP filtering.
Test this pattern →IPv6 Address
((?:[0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}|(?:[0-9A-Fa-f]{1,4}:){1,7}:|(?:[0-9A-Fa-f]{1,4}:){1,6}:[0-9A-Fa-f]{1,4}|(?:[0-9A-Fa-f]{1,4}:){1,5}(?::[0-9A-Fa-f]{1,4}){1,2}|(?:[0-9A-Fa-f]{1,4}:){1,4}(?::[0-9A-Fa-f]{1,4}){1,3}|(?:[0-9A-Fa-f]{1,4}:){1,3}(?::[0-9A-Fa-f]{1,4}){1,4}|(?:[0-9A-Fa-f]{1,4}:){1,2}(?::[0-9A-Fa-f]{1,4}){1,5}|[0-9A-Fa-f]{1,4}:(?::[0-9A-Fa-f]{1,4}){1,6}|:(?::[0-9A-Fa-f]{1,4}){1,7}|::)Matches: Matches full and shorthand IPv6 addresses, including loopback (::1).
Use case: IPv6 network validation, firewall rule auditing, and cloud infrastructure config.
Test this pattern →MAC Address
^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$Matches: Validates a MAC address in either colon-separated or hyphen-separated format.
Use case: Network device inventory, DHCP configuration, and hardware identification.
Test this pattern →Phone (US)
^\+?1?\d{10}$Matches: Matches a 10-digit US phone number with optional +1 country code.
Use case: US phone number validation in checkout forms, contact pages, and user profiles.
Test this pattern →Date (ISO 8601)
^\d{4}-\d{2}-\d{2}$Matches: Validates a date in YYYY-MM-DD ISO 8601 format.
Use case: Date picker validation, database input sanitization, and API request filtering.
Test this pattern →Time (24-hour)
^([01]\d|2[0-3]):[0-5]\d(:[0-5]\d)?$Matches: Matches 24-hour time format (HH:MM) with optional seconds.
Use case: Time input validation, scheduling systems, and log timestamp parsing.
Test this pattern →UUID v4
^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$Matches: Validates a UUID version 4 — a 128-bit identifier with a specific version nibble.
Use case: Primary key validation, API resource IDs, distributed system identifiers.
Test this pattern →Base64
^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$Matches: Validates a Base64-encoded string with proper padding.
Use case: Data URI validation, API payload checks, encoded binary verification.
Test this pattern →Hex Color
^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$Matches: Matches 3-digit and 6-digit hex color codes, with or without leading #.
Use case: CSS color validation, theme configuration, and design system tooling.
Test this pattern →Credit Card Number
^\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}$Matches: Matches a 16-digit credit card number with optional separators (spaces or hyphens).
Use case: Payment form validation, PCI-compliant input masking, and order processing.
Test this pattern →ZIP Code (US)
^\d{5}(-\d{4})?$Matches: Validates a US ZIP code — 5-digit or ZIP+4 format.
Use case: Shipping address forms, location-based services, and geocoding inputs.
Test this pattern →Password Strength
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$Matches: Requires minimum 8 characters with at least one lowercase letter, one uppercase letter, and one digit.
Use case: Password policy enforcement, account registration, and security compliance.
Test this pattern →Extraction Patterns
Patterns for pulling specific elements out of larger text bodies — ideal for web scraping, log parsing, and content analysis.
HTML Tags
<[^>]+>Matches: Matches any HTML tag, including opening, closing, and self-closing tags.
Use case: Stripping HTML from rich text, scraping web content, and sanitizing user input.
Test this pattern →Links from HTML
<a\s+(?:[^>]*?\s+)?href="([^"]*)"Matches: Extracts the href attribute value from anchor tags.
Use case: Link harvesting, web scraping, SEO audits, and content migration.
Test this pattern →Images from HTML
<img\s+[^>]*?src="([^"]*)"Matches: Extracts the src attribute value from image tags.
Use case: Image gallery generation, content migration, and media asset inventory.
Test this pattern →Numbers
\d+(?:\.\d+)?Matches: Matches integers and decimal numbers in text.
Use case: Data extraction from documents, log parsing, and financial report analysis.
Test this pattern →Words
\b\w+\bMatches: Matches individual word tokens bounded by non-word characters.
Use case: Word counting, text tokenization, and search indexing.
Test this pattern →Sentences
[^.!?\s][^.!?]*[.!?]Matches: Matches complete sentences ending with period, exclamation, or question mark.
Use case: Text summarization, natural language processing, and content analysis.
Test this pattern →Quoted Strings (Double)
"([^"]*)"Matches: Extracts text enclosed in double quotes.
Use case: Config file parsing, log analysis, and data serialization inspection.
Test this pattern →JSON Keys
"([^"]+)"\s*:Matches: Extracts key names from JSON objects.
Use case: JSON schema generation, API response analysis, and data transformation.
Test this pattern →Domain Names
\b(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}\bMatches: Matches domain names including subdomains and TLD.
Use case: URL validation, email domain extraction, and network security analysis.
Test this pattern →File Extensions
\.\w+$Matches: Matches the file extension at the end of a filename.
Use case: File type classification, upload validation, and content-type detection.
Test this pattern →Replacement & Formatting Patterns
Patterns for transforming text — cleaning whitespace, converting case, formatting numbers, and removing duplicates. Use these with regex replace operations.
Remove Extra Whitespace
\s+Matches: Matches one or more whitespace characters for collapsing into a single space.
Use case: Normalizing user input, minifying HTML/CSS, and cleaning pasted text.
Test this pattern →Remove HTML Tags
<[^>]+>Matches: Matches all HTML tags for stripping markup from text.
Use case: Converting rich text to plain text, sanitizing content, and extracting readable copy.
Test this pattern →Add Line Breaks After Period
\.(?=\s+[A-Z])Matches: Finds periods followed by a space and capital letter — ideal for sentence splitting.
Use case: Text formatting, document reformatting, and sentence segmentation.
Test this pattern →Convert camelCase to snake_case
([a-z])([A-Z])Matches: Finds boundaries between lowercase and uppercase letters for case conversion.
Use case: Code refactoring, API field normalization, and cross-language identifier mapping. Replace with $1_$2 (then lowercase the result).
Test this pattern →Strip Leading/Trailing Whitespace
^\s+|\s+$Matches: Matches whitespace at the start or end of a string.
Use case: Input sanitization, log cleaning, and data normalization. Replace with empty string.
Test this pattern →Remove Duplicate Words
\b(\w+)\s+\1\bMatches: Finds consecutive repeated words in text.
Use case: Proofreading, text cleanup, and content editing. Replace with $1 to keep a single occurrence.
Test this pattern →Add Comma to Numbers
(\d)(?=(\d{3})+(?!\d))Matches: Adds thousands separators to large numbers using lookahead.
Use case: Number formatting for display, financial reporting, and data visualization. Replace with $1,.
Test this pattern →Tips for Using Regex Patterns
Always Test First
Regex behaves differently across languages and engines. Test every pattern in the Regex Tester before deploying it to production. What matches in JavaScript may differ from Python, PCRE, or Rust.
Anchor When Validating
Use ^ and $ anchors for validation patterns to ensure the entire string matches, not just a substring. Without anchors, a pattern like \\d4 would match “abc12345”.
Watch for Catastrophic Backtracking
Patterns with nested quantifiers like (a+)+b can cause exponential backtracking on non-matching strings. Keep patterns simple, use possessive quantifiers where available, and test with edge cases.
Use Flags for Precision
The g flag finds all matches (not just the first). i makes matching case-insensitive. m makes ^ and $ match line boundaries. Choose flags intentionally.
Related Tools & References
Explore these related tools and references to get the most out of regular expressions: