Common Regex Patterns
A static regex cheat sheet with practical patterns, pass/fail examples, performance warnings, and a live browser-side matcher.
Regex patterns people actually search for
This directory focuses on high-utility patterns developers, operators, and analysts reuse constantly: validation, extraction, and cleanup. Each page includes a regex, practical test cases, code snippets, and a live in-browser matcher so you can test an input string without leaving the page.
Curated regex patterns grouped by validation, extraction, and replace workflows.
Validation Patterns
- ValidationSafe starter
Regex for Valid Email Address
Use this when you need a lightweight email format check in forms or ETL cleanup. It avoids spaces and requires a single @ plus a dot-delimited domain.
Pattern/^[^\s@]+@[^\s@]+\.[^\s@]+$/i - ValidationSafe starter
Regex for URL Slug
A clean slug matcher for lowercase SEO paths. It permits internal hyphens while blocking uppercase letters, spaces, and repeated separators.
Pattern/^[a-z0-9]+(?:-[a-z0-9]+)*$/ - ValidationSafe starter
Regex for Strong Password
This pattern enforces a minimum length plus lower, upper, digit, and symbol presence. It is useful for UI hints, but real password policy should still be enforced server-side.
Pattern/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z\d]).{12,}$/ - ValidationSafe starter
Regex for UUID v4
UUID v4 patterns help validate request IDs, webhook event IDs, and client-generated identifiers without accepting the wrong version bit.
Pattern/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i - ValidationSafe starter
Regex for IPv4 Address
Use this when you need to validate dotted IPv4 literals and reject octets outside the 0-255 range.
Pattern/^(?:25[0-5]|2[0-4]\d|1?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|1?\d?\d)){3}$/ - ValidationSafe starter
Regex for Hex Color
A simple validator for 3- or 6-digit hex colors, useful in design tooling and theme settings.
Pattern/^#?(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/ - ValidationSafe starter
Regex for Semantic Version
Semantic version matching is useful in release tooling, changelog parsing, and dependency dashboards where you need to distinguish versions from free text.
Pattern/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/ - ValidationSafe starter
Regex for Credit Card Number Format
This is a format-only pattern for card-like numbers. It is appropriate for client-side input cleanup, but real validation still needs Luhn checks and payment processor rules.
Pattern/^(?:\d[ -]*?){13,19}$/ - ValidationReDoS risk
Regex with Nested Quantifiers
This is a teaching pattern for catastrophic backtracking risk. It looks simple, but nested quantifiers can turn certain non-matching inputs into expensive regex evaluations.
Pattern/^(a+)+$/
Extraction Patterns
- ExtractionSafe starter
Regex to Extract URLs
A pragmatic URL extractor for logs, markdown drafts, and support transcripts where you want to capture obvious HTTP and HTTPS links.
Pattern/https?:\/\/[^\s"'<>]+/gi - ExtractionSafe starter
Regex to Extract HTML Tags
Useful when you need quick tag-level extraction for diagnostics, not full HTML parsing. It matches opening and closing tags with their attributes.
Pattern/<\/?[A-Za-z][^>]*>/g - ExtractionSafe starter
Regex to Extract JSON Keys
A quick way to pull top-level and nested key tokens from JSON-like text during debugging or migration prep.
Pattern/"([^"]+)"\s*:/g - ExtractionSafe starter
Regex to Extract Quoted Text
Use this when you need content between double quotes while tolerating escaped characters in logs or config snippets.
Pattern/"([^"\\]*(?:\\.[^"\\]*)*)"/g - ExtractionSafe starter
Regex to Extract Markdown Links
This pattern helps pull markdown links into audits, migrations, and content QA workflows.
Pattern/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g
Replace Patterns
- ReplaceSafe starter
Regex to Replace Repeated Whitespace
Use this before `.replace()` when normalizing messy copy, scraped text, or imported CSV fields with inconsistent spacing.
Pattern/\s+/g - ReplaceSafe starter
Regex to Strip Non-Digits
This is useful when cleaning phone numbers, account references, or IDs into a digits-only form before formatting or validation.
Pattern/\D+/g - ReplaceSafe starter
Regex to Collapse Blank Lines
Helpful when normalizing pasted docs, generated markdown, or support transcripts with too much vertical space.
Pattern/\n{3,}/g - ReplaceSafe starter
Regex to Remove HTML Comments
Use this in cleanup scripts when you need to strip comment blocks from HTML exports or email templates.
Pattern/<!--[\s\S]*?-->/g