Regex Pattern Generator
Browse common regex patterns for email, URL, phone, IP address, date, and more. Each pattern includes a breakdown explanation and live testing. 100% client side.
Pattern Breakdown
Examples (click to test)
About Regular Expressions
Regular expressions (regex) are patterns used to match character combinations in strings. They are essential for form validation, data extraction, search and replace, and input sanitization.
When to Use Regex
- Form field validation (email, phone, etc.)
- Parsing log files and extracting data
- Search and replace in text editors and code
- Input sanitization and filtering
- URL routing and rewriting
Common Regex Tokens
^- start of string$- end of string\d- any digit (0-9)\w- word character (a-z, A-Z, 0-9, _)\s- whitespace+- one or more*- zero or more?- zero or one (optional){n,m}- between n and m occurrences
Related Tools
- Regex Tester - test and debug custom regex patterns
- Diff Checker - compare text differences
- Word Counter - count words, characters, sentences
Common Regex Patterns You Don't Have to Memorize
Regular expressions are the universal text-pattern language — every IDE, every shell, every database, every log analyzer supports some flavor. The downside: even experienced engineers write a fresh email regex from scratch every six months because the canonical version isn't memorable. This page collects the patterns you'll reach for repeatedly, with notes on edge cases and flavor differences.
Patterns that come up daily
- Email (RFC 5322 lite):
^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$. Reject empty, multiple @, weird domains. Won't accept every legal email — but every email it accepts is legal. - URL:
^https?://[\w.-]+(?::\d+)?(?:/.*)?$. Matches http and https with optional port and path. - IPv4:
^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$. The simple\d+\.\d+\.\d+\.\d+matches "999.999.999.999"; this one doesn't. - UUID:
^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$. - ISO date (YYYY-MM-DD):
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$. - Hex color:
^#(?:[0-9a-fA-F]{3}){1,2}$. - Slug:
^[a-z0-9]+(?:-[a-z0-9]+)*$. - Strong password (8+, upper, lower, digit, special):
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_]).{8,}$.
Pitfalls and flavor gotchas
- Anchors. Without
^and$(or\A/\z), your regex matches anywhere in the string. - Greedy vs lazy.
.*grabs as much as possible;.*?the minimum. Wrong choice on HTML parsing causes off-by-tag matches. - Catastrophic backtracking. Patterns like
(a+)+bcan take exponential time on input that doesn't match. Use possessive quantifiers ((?>a+)+b) where supported. - Unicode.
\win JavaScript only matches ASCII letters/digits/underscore. Use[\p{L}\p{N}_]with theuflag for full Unicode. - Multiline mode. Without
mflag,^and$match start/end of input, not lines. - Don't parse HTML/XML/JSON with regex. Use a parser. The classic SO answer applies.
When regex is the wrong tool
Email validation: just send a confirmation link. URL validation: use new URL(input). Phone numbers: use libphonenumber. Dates: use a date library. Regex is great for tokenizing, splitting, and quick filtering — not for validating structured data.
This page is a cheat sheet plus an interactive tester running entirely in your browser. For deeper text-processing, see our developer tools roundup.
Frequently Asked Questions
Why is my email regex rejecting legitimate addresses like user+tag@gmail.com?
Most "simple" email regex patterns block + or - or extended TLDs. The pattern shown above accepts both. For full RFC 5322 you need a much longer regex, or just send a confirmation email.
How do I prevent catastrophic backtracking?
Avoid nested quantifiers like (a+)+. Use atomic groups or possessive quantifiers where the engine supports them. Test with adversarial inputs.
Is JavaScript regex the same as Python regex?
Mostly the same syntax with different libraries. Differences: lookbehind support, named-group syntax, Unicode handling, and a few esoteric features.
Should I use regex to validate JSON or HTML?
No. Use a real parser. Regex on structured formats is a known anti-pattern.