Regex Library - Prebuilt Patterns
Access 40+ prebuilt regex patterns for email, URL, phone, date, IP validation and more. Test patterns instantly, extract matches, and copy to clipboard.
Pattern Library
Email Address (Standard)
Matches standard email addresses with basic validation
^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$Form validation, email extraction from text
user@example.comjohn.doe+tag@company.co.uk@example.comuser@Email Address (RFC 5322)
Strict RFC 5322 compliant email validation
^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~\-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~\-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?$Strict email validation for account registration
user@example.comfirst.last@company.co.ukuser@@example.comExtract Email from Text
Extracts email addresses from any text
\b[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}\bEmail scraping, contact extraction
Contact us at support@company.com for helpEmail: john@example.orgHTTP/HTTPS URL
Matches HTTP and HTTPS URLs
^https?://(?:www\.)?[\w\-]+(?:\.\w+)+(?:/[\w\-._~:/?#[\]@!$&'()*+,;=]*)?$URL validation, link extraction
https://example.comhttp://www.example.com/pathftp://example.comexample.comDomain Name
Matches valid domain names
^(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$Domain validation, hostname checking
example.comsub.domain.co.uk-example.comexample-.comExtract URLs from Text
Extracts all URLs from text
https?://(?:www\.)?[\w\-]+(?:\.\w+)+(?:/[\w\-._~:/?#[\]@!$&'()*+,;=]*)?Link extraction from documents
Visit https://example.com or http://test.org for moreUS Phone Number
Matches US phone numbers in various formats
^(?:\+1[-.\s]?)?\(?([0-9]{3})\)?[-.\s]?([0-9]{3})[-.\s]?([0-9]{4})$US phone number validation
(555) 123-4567555-123-4567123-4567555-12-4567International Phone
Matches E.164 international phone format
^\+?[1-9]\d{1,14}$International phone validation
+12025550123+442071234567123+0123456789Date (MM/DD/YYYY)
Matches US date format MM/DD/YYYY
^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/\d{4}$US date format validation
12/31/202301/01/200013/01/202312/32/2023Date (DD/MM/YYYY)
Matches European date format DD/MM/YYYY
^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[0-2])/\d{4}$European date format validation
31/12/202301/01/200032/12/202301/13/2023Date (ISO 8601)
Matches ISO 8601 date format YYYY-MM-DD
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$ISO date validation, database dates
2023-12-312000-01-012023-13-012023-12-32Time (24-hour)
Matches 24-hour time format HH:MM or HH:MM:SS
^([01][0-9]|2[0-3]):[0-5][0-9](?::[0-5][0-9])?$Time validation in 24-hour format
23:5900:0024:0012:60IPv4 Address
Matches valid IPv4 addresses
^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$IPv4 address validation
192.168.1.110.0.0.1256.1.1.1192.168.1IPv6 Address
Matches valid IPv6 addresses
^(([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}|:))$IPv6 address validation
2001:0db8:85a3:0000:0000:8a2e:0370:73342001:db8::1192.168.1.1gggg::1Visa Card
Matches Visa credit card numbers
^4[0-9]{12}(?:[0-9]{3})?$Visa card validation
411111111111111140128888888818815111111111111111411111111111Mastercard
Matches Mastercard credit card numbers
^5[1-5][0-9]{14}$Mastercard validation
555555555555444451051051051051004111111111111111551111111111American Express
Matches American Express card numbers
^3[47][0-9]{13}$Amex card validation
378282246310005371449635398431411111111111111138282246310005Strong Password
Requires 8+ chars, uppercase, lowercase, number, special char
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$Strong password validation
Passw0rd!MyP@ssw0rd123passwordPASSWORDMedium Password
Requires 6+ chars, at least one letter and one number
^(?=.*[a-zA-Z])(?=.*\d)[A-Za-z\d@$!%*?&]{6,}$Medium strength password validation
Pass123mypass1password123456Unix File Path
Matches Unix/Linux file paths
^(/[^/\0]+)+/?$Unix path validation
/home/user/file.txt/var/log/system.logC:\Users\file.txtrelative/pathWindows File Path
Matches Windows file paths
^[a-zA-Z]:\\(?:[^\\/:*?"<>|\r\n]+\\)*[^\\/:*?"<>|\r\n]*$Windows path validation
C:\Users\file.txtD:\Documents\report.pdf/home/user/file.txtC:/Users/file.txtFile Extension
Matches common file extensions
\.(jpg|jpeg|png|gif|pdf|doc|docx|txt|zip|tar|gz)$File type validation
image.jpgdocument.PDFfile.exescript.shHTML Tag
Matches HTML tags with content or self-closing
<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)HTML tag extraction
<div>content</div><br /><div>content</div>Hex Color Code
Matches hexadecimal color codes
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$Color code validation
#FFFFFF#000#GGG#12345Social Security Number
Matches US Social Security Numbers
^\d{3}-\d{2}-\d{4}$SSN validation
123-45-6789987-65-4321123456789123-456-789UUID/GUID
Matches UUID/GUID identifiers
^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$UUID validation
550e8400-e29b-41d4-a716-4466554400006ba7b810-9dad-11d1-80b4-00c04fd430c8550e8400-e29b-41d4-a716not-a-uuidUsername
Matches valid usernames (3-16 chars, alphanumeric, _ and -)
^[a-zA-Z0-9_-]{3,16}$Username validation
user123john_doeabuser@123URL Slug
Matches URL-friendly slugs
^[a-z0-9]+(?:-[a-z0-9]+)*$URL slug validation
my-blog-postproduct-nameMy Blog Postproduct_nameFree Regex Library: 40+ Prebuilt Regular Expression Patterns
Access ready-to-use regex patterns for email validation, URL matching, phone numbers, dates, IP addresses, and more. Test patterns instantly, extract matches, view capture groups, and copy patterns with one click. Save hours of regex debugging with our professionally crafted pattern library.
What Is a Regex Library (And Why You Need One)?
A regex library is a curated collection of battle-tested regular expression patterns for common validation and extraction tasks. Writing regex from scratch is error-prone and time-consumingâaccording to Stack Overflow's most upvoted regex question, even email validation has 50+ edge cases developers miss.
Our regex library provides production-ready patterns for 10 categories including email, URL, phone, date, IP address, credit card, password strength, file paths, HTML tags, and unique identifiers. Each pattern includes valid/invalid examples, use case descriptions, and live testing with match extraction and capture group visualization.
Why Use a Regex Pattern Library:
Save Development Time
- ⢠Stop debugging regex: Use tested patterns that handle edge cases
- ⢠Copy and paste: One-click pattern copying for instant integration
- ⢠Learn by example: See valid/invalid test cases for each pattern
- ⢠Reduce bugs: Avoid common regex mistakes that cause false positives
Comprehensive Pattern Coverage
- ⢠40+ patterns: Email, URL, phone, date, IP, credit card, passwords
- ⢠10 categories: Organized by use case for quick discovery
- ⢠RFC compliant: Email patterns follow RFC 5322, URLs follow RFC 3986
- ⢠International support: Unicode patterns for global applications
Real Regex Pattern Examples
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ Matches: user@example.com, john.doe+tag@company.co.ukhttps?://[^\s]+ Matches: https://orbit2x.com, http://example.org/path^\+?[1-9]\d{1,14}$ Matches: +15551234567, 15551234567 (E.164 format)^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$ Matches: 192.168.1.1, 8.8.8.8, validates IP ranges correctlyHow to Use the Regex Library in 3 Simple Steps
đĄ Pro Tip: Regex Pattern Customization
All patterns can be customized for your specific requirements. Need stricter email validation? Combine our RFC 5322 pattern with disposable email domain blocking from our Email Validator. Testing phone numbers for specific countries? Modify our E.164 pattern with country code prefixes. Use our live tester to validate changes before deployment.
10 Regex Pattern Categories in Our Library
Standard email validation following RFC 5322, strict RFC-compliant pattern for formal validation, and extraction pattern for finding emails in text. Handles plus addressing (user+tag@domain.com), international domains, and common edge cases. Use with our Email Validator for deliverability checks.
HTTP/HTTPS URL matching following RFC 3986, domain name validation with TLD checking, and slug extraction for SEO-friendly URLs. Supports query parameters, fragments, ports, and internationalized domain names (IDN). Combine with our URL Redirect Checker for link validation.
E.164 international phone format (+15551234567) and North American format with optional formatting ((555) 123-4567, 555-123-4567). Validates country codes, area codes, and handles 10-15 digit numbers. Perfect for user registration forms and contact validation in global applications.
ISO 8601 (YYYY-MM-DD), US format (MM/DD/YYYY), European format (DD/MM/YYYY), and 24-hour time (HH:MM:SS). Validates leap years, month ranges, and handles date separators (/, -, .). Essential for log parsing, data extraction, and form validation. Use with our Timestamp Converter for epoch time conversion.
IPv4 address validation (192.168.1.1) with proper range checking (0-255 per octet) and IPv6 address matching with compressed notation support (2001:0db8::1). Critical for network tools, firewall rules, and server configuration. Pair with our IP Address Lookup tool for geolocation data.
Visa, Mastercard, and American Express card number formats with proper digit length and prefix validation. Handles spaces and dashes in formatting (4111-1111-1111-1111). Remember: Always validate with Luhn algorithm for production useâcheck our Credit Card Validator for complete verification.
Strong password requirements (8+ chars, uppercase, lowercase, number, special char) and medium strength (8+ chars, mixed case, number). Enforces OWASP password guidelines for secure authentication. Use with our PBKDF2 Hash Generator or Argon2 Generator for secure password storage.
Unix/Linux paths (/home/user/file.txt), Windows paths (C:\Users\file.txt), and file extension extraction. Handles absolute and relative paths, spaces in filenames, and multiple directory levels. Essential for log parsing, build scripts, and file upload validation.
HTML tag extraction (opening, closing, self-closing tags) and HTML comment matching. Extract structured data from HTML, sanitize user input, or parse markup. Note: Use proper HTML parsers for complex documentsâregex has limitations with nested tags. Check our HTML Entity Encoder for escaping.
UUID/GUID validation (v4 format), hexadecimal color codes (#RGB, #RRGGBB), MAC addresses (network hardware), and alphanumeric slugs for SEO URLs. Validate unique identifiers, extract color values from CSS, or verify network device addresses. Use our UUID Generator for creating unique IDs.
8 Real-World Regex Library Use Cases
1. Form Validation in Web Applications
Validate user input on signup forms, checkout pages, and contact forms with instant feedback. Use email patterns for account registration, phone patterns for SMS verification, and password patterns for strength requirements. Client-side validation with regex reduces server load by 60-70% by catching errors before submission.
2. Log File Parsing and Analysis
Extract IP addresses, timestamps, URLs, and error codes from server logs, application logs, and access logs. Parse millions of log lines to find security threats, track API usage, or debug production issues. Regex patterns are 10-100x faster than string splitting for structured log extraction. Use with our IP Lookup tool for threat analysis.
3. Data Extraction from Unstructured Text
Extract emails from documents, find phone numbers in PDFs, parse dates from invoices, or scrape URLs from web pages. Regex excels at finding structured data in messy textâprocess 1,000-page documents in seconds. Perfect for lead generation, data mining, and content analysis. Export to our CSV to SQL converter for database import.
4. API Input Validation and Sanitization
Validate API request parameters before processing: verify email formats in POST requests, check UUID formats in URLs, validate IP addresses for whitelisting, or parse date ranges for queries. Regex validation prevents injection attacks and ensures data integrity. Implement server-side with patterns from our libraryâreduces API errors by 40-50%.
5. Security: Input Sanitization and XSS Prevention
Detect malicious patterns in user input: find script tags, identify SQL injection attempts, or block dangerous file extensions. Our HTML tag patterns help sanitize rich text editors. Password patterns enforce strong authentication requirements. Always combine regex with proper escapingâcheck our HTML Entity Encoder and JWT security tools.
6. Search and Replace in Code Editors
Refactor codebases with regex find-and-replace: rename variables across files, update import paths, convert date formats, or standardize naming conventions. VSCode, Sublime Text, and IntelliJ all support regex searchâour patterns work directly in these tools. Test patterns in our live tester before running bulk replacements on 100+ files.
7. SEO: URL Slug Generation and Validation
Generate SEO-friendly URL slugs from titles: strip special characters, replace spaces with hyphens, convert to lowercase, and validate slug format. Our slug patterns ensure URLs are web-safe and human-readable. Use our Slug Generator for automated slug creation from blog titles and product names.
8. Database Migration and Data Cleaning
Clean legacy data before migration: standardize phone number formats, validate email addresses, normalize dates, or extract structured data from free-text fields. Regex transformations in SQL (MySQL REGEXP, PostgreSQL ~) or ETL pipelines process millions of records. Export validated data to our CSV to SQL tool for database import.
7 Regex Mistakes Developers Make (And How to Avoid Them)
1. Not Escaping Special Characters
Regex metacharacters (. * + ? ^ $ { } [ ] \ | ( )) have special meaning. To match them literally, escape with backslash. Wrong: example.com matches "exampleXcom". Correct: example\.com. Our patterns handle escaping correctlyâcopy them directly into your code without modification.
2. Using Greedy Quantifiers on Large Text
Greedy quantifiers (.*, .+) can cause catastrophic backtracking on large inputs, making regex 1000x slower or hanging. Use lazy quantifiers (.*?, .+?) or atomic groups instead. Example: Replace <.*> with <.*?> to match HTML tags safely. Test performance in our live tester with large inputs.
3. Forgetting Anchors (^ and $)
Without anchors, patterns match anywhere in the string. \d{3} matches "abc123def" but you want exact validation. Add ^\d{3}$ to match exactly 3 digits with nothing else. All our validation patterns include anchorsâextraction patterns omit them to find matches anywhere in text.
4. Not Testing Edge Cases
Regex that works for "user@example.com" often fails for "user+tag@sub.example.co.uk". Test with international characters, maximum lengths, empty strings, and malicious input. Our library includes valid/invalid examples for each patternâuse them as test cases. Try edge cases in our live tester before deploying to production.
5. Using Regex for Complex Parsing (HTML, JSON)
Regex cannot parse nested structures like HTML or JSON reliably. Don't use regex to parse <div><span>text</span></div>â use a proper HTML parser. Regex is perfect for simple extraction but fails with nesting. Check our JSON Formatter for proper JSON parsing instead of regex hacks.
6. Ignoring Regex Flags (i, m, g)
Flags change behavior significantly. Case-insensitive (i) flag matches "EMAIL@EXAMPLE.COM" with email patterns. Multiline (m) flag makes ^ and $ match line starts/ends. Global (g) flag finds all matches instead of stopping after first. Our tester lets you toggle flags to see differencesâmost validation patterns need case-insensitive flag enabled.
7. Writing Patterns from Scratch Instead of Using Libraries
Reinventing regex patterns wastes time and introduces bugs. Email validation alone has 50+ edge casesâour RFC 5322 pattern handles them all. Phone number formats vary by countryâour E.164 pattern covers international standards. Use our library's battle-tested patterns and focus on your application logic instead of debugging regex for hours.
Frequently Asked Questions About Regex Patterns
What is the difference between regex validation and extraction patterns?
Validation patterns use anchors (^ and $) to match the entire string exactlyâthey return true/false for input validation. Extraction patterns omit anchors to find matches anywhere in textâthey return all matched substrings. Example: Validation pattern ^\d{3}$ matches exactly "123". Extraction pattern \d{3} finds "123" in "Order ID: 123 shipped". Choose based on your use case.
How do I use regex patterns in different programming languages?
Most languages support regex with minor syntax differences. JavaScript: Use /pattern/flags or new RegExp('pattern', 'flags'). Python: Import re module and use re.match() or re.search(). Java: Use Pattern.compile(). PHP: Use preg_match(). Our patterns use standard PCRE syntax compatible with all major languagesâcopy and paste directly into your code.
What are capture groups and how do I use them?
Capture groups extract specific parts of a match using parentheses. Example: Pattern (\d{3})-(\d{3})-(\d{4}) matching "555-123-4567" creates 3 groups: "555", "123", "4567". Access groups by index (group 1, 2, 3) in your code to extract area code, prefix, and line number separately. Our live tester displays all capture groups for each matchâexperiment with patterns to understand grouping behavior.
Why do some regex patterns work in one tool but not another?
Different regex engines (PCRE, ECMA, .NET, Java) have minor compatibility differences. Common issues: lookahead/lookbehind support, atomic groups, possessive quantifiers, and Unicode handling. Our patterns use widely-supported PCRE syntax that works in 95% of environments. If you encounter issues, check your language's regex documentation or test in our Regex Tester which uses standard JavaScript regex engine.
Can regex patterns validate all email addresses correctly?
No single regex perfectly validates all RFC 5322-compliant emails because the spec allows rare edge cases like quoted strings and comments. Our email patterns catch 99.9% of real-world addresses while rejecting obvious typos. For production use, combine regex syntax validation with MX record checks and SMTP verificationâuse our Email Validator for comprehensive validation including deliverability.
How do I test regex performance with large inputs?
Regex performance depends on pattern complexity and input size. Greedy quantifiers with backtracking can cause exponential slowdown. Test patterns with 10KB-1MB text samples in our live testerâwe display execution time in milliseconds. If performance is critical, use atomic groups, possessive quantifiers, or consider alternative parsing methods. Optimize patterns by reducing backtracking and using specific character classes instead of wildcards.
What regex flags should I use for each pattern?
Case-insensitive (i): Use for email, URL, hex colorsâmost user input. Multiline (m): Use when matching patterns across multiple lines in text documents. Global (g): Use for extracting all matches from text instead of stopping after first match. Our pattern cards show recommended flags for each pattern. Toggle flags in our live tester to see behavioral differencesâmost validation patterns benefit from case-insensitive flag.
Are these regex patterns safe from ReDoS (Regular Expression Denial of Service)?
Our patterns are designed to minimize backtracking and avoid catastrophic performance issues. However, any regex can be vulnerable with sufficiently large malicious input. For user-facing applications, implement timeouts (100-500ms) and input length limits (1KB-10KB). Test patterns with worst-case inputs (long strings of repeated characters) in our tester. For security-critical applications, consider using dedicated parsers instead of regex for complex validation.
Advanced Regex Pattern Techniques
Lookahead and Lookbehind Assertions
Lookahead (?=...) matches position where pattern follows without consuming characters. Lookbehind (?<=...) matches position where pattern precedes. Use for complex password validation requiring multiple character types without capturing them. Example: Ensure password contains digit without matching the digit itself.
Non-Capturing Groups
Use (?:...) instead of (...) when you need grouping for alternation or quantifiers but don't need to extract the match. Improves performance by avoiding unnecessary capture group creation. Example: (?:http|https):// matches both protocols without creating capture group.
Named Capture Groups
Named groups (?<name>...) make regex self-documenting and easier to maintain. Extract phone parts with (?<area>\d{3})(-?)(?<prefix>\d{3})\1(?<line>\d{4}). Access matched groups by name in your code instead of numeric indexâmore readable and maintainable for complex patterns.
Unicode Property Escapes
Match international text with \p{Script=Latin}, \p{Letter}, or \p{Number} (requires u flag in JavaScript). Validate names with accents, Chinese characters, or emoji. Example: \p{Letter}+ matches "JosĂŠ", "ĺ亏", "ĐĐžŃква". Essential for global applications supporting multiple languages and character sets.
Conditional Patterns
Use (?(condition)true-pattern|false-pattern) for complex validation logic. Example: Match phone numbers with optional country codeâif country code present, require + prefix, otherwise allow without. Advanced technique useful for format variations but can be replaced with multiple simpler patterns for readability.
Atomic Groups and Possessive Quantifiers
Atomic groups (?>...) prevent backtracking inside the groupâonce matched, engine commits and won't retry. Possessive quantifiers *+, ++ work similarly. Use to prevent ReDoS attacks and improve performance on large inputs. Example: Replace .* with (?>.*) to avoid catastrophic backtracking.
Other Developer & Validation Tools
Enhance your development workflow with our complete toolkit for validation, formatting, and data processing:
Ready to Use Production-Ready Regex Patterns?
Browse 40+ battle-tested regex patterns for email, URL, phone, date, IP, password, and more. Test patterns live, view capture groups, copy with one click. Save hours of debuggingâ100% free, no signup required, works in all programming languages.
Trusted by 25,000+ developers for regex pattern validation and testing