Regex Generator for Common Patterns
Pick email, URL, IPv4, IPv6, date, phone, UUID or hex color and get a vetted regex pattern with an explanation and verified sample matches.
Worked examples
- Email address pattern
The most-requested pattern on this tool — a practical, typo-catching email pattern rather than a full RFC 5322 implementation, which is rarely what people actually want.
- IPv4 address pattern
Demonstrates why a naive \d{1,3}(\.\d{1,3}){3} pattern is wrong — this one rejects out-of-range octets by construction.
- UUID pattern
A generic UUID shape check, useful for validating form input or API identifiers without needing to know which UUID version was used.
What this tool does
This tool hands you a ready-to-use, vetted regular expression for eight commonly needed formats — email address, URL, IPv4 address, IPv6 address, ISO 8601 date, US-style phone number, UUID and hex color code — along with a plain-English explanation and three sample values that are verified against the pattern every time the page runs.
When you need it
- Validating a form field or API parameter without writing and debugging a regex from scratch, or copying one from an unverified forum answer.
- Understanding what a regex you found elsewhere is actually checking, by comparing it against one of these known-good patterns for the same format.
- Quickly confirming that a value's shape is plausible — a UUID looks like a UUID, an IPv4 octet is actually in range — before deeper validation.
- Learning how a well-constructed pattern for a common format is put together, as a starting point for writing your own variant.
Why "vetted" doesn't mean "perfect"
No regex fully validates email addresses or URLs per their official specifications — RFC 5322 email addresses, in particular, allow syntax so unusual that almost no real-world validator implements it completely, and even the ones that try are dozens of lines long. These patterns are deliberately practical: tuned to catch the overwhelming majority of real typos and malformed input without being needlessly permissive or needlessly strict. For anything security-sensitive — verifying an email is truly deliverable, or that a URL is safe to fetch — pair pattern matching with an actual verification step (a confirmation email, a DNS lookup), not regex alone.
What makes the IPv4 and IPv6 patterns different from the obvious version
A naive IPv4 pattern like \d+\.\d+\.\d+\.\d+ would accept 999.999.999.999, which isn't a valid address. The pattern here constrains each octet to the 0–255 range explicitly, which is why it looks longer than the naive version. The IPv6 pattern handles both the fully expanded eight-group form and the :: zero-compression shorthand that almost all real-world IPv6 addresses actually use — a pattern that only matched the expanded form would reject the vast majority of addresses you'd encounter in practice.
Verified against live samples
Every time you select a format, the three sample values shown aren't a static, trust-me list — they're tested against the pattern in the same computation that produces the pattern itself, and the result of each test is shown. If a sample ever failed to match its own pattern, that would be immediately visible rather than silently wrong.
Known gaps worth knowing about
The samples shown are all values that should match, so they demonstrate that a pattern accepts good input, not that it rejects bad input; use the regex tester to try your own bad values. Specific looseness we checked: the email pattern accepts consecutive dots in the local part (a..b@c.com) and a domain label that starts with a hyphen; the phone pattern accepts unbalanced parentheses such as (415 555-2671 and has no country-code prefix; the date pattern accepts 2026-02-30; the URL pattern rejects localhost, IP-address hosts and internationalized domain names; the hex color pattern omits the 4- and 8-digit alpha forms; and the IPv6 pattern does not accept zone IDs (%eth0) or embedded IPv4 notation such as ::ffff:1.2.3.4.
Using the pattern elsewhere
Copy the pattern string into your own code's RegExp (or equivalent in another language) along with the listed flags, if any. The syntax used across all eight patterns — character classes, quantifiers, alternation — is standard across JavaScript, Python, PCRE and most other regex engines, so portability generally isn't a concern here.
Frequently asked questions
- Are these patterns guaranteed to catch every edge case?
- No regex fully validates email or URL syntax per spec — these are deliberately practical patterns tuned to catch common typos and malformed input, which is what most real-world validation needs.
- How do I know the pattern actually works?
- Each pattern is tested live against its three sample values every time the page runs, and the result is shown per sample — this isn't a static, unverified snippet.
- Can I use these patterns outside JavaScript?
- The syntax used here (character classes, quantifiers, alternation) is standard across JavaScript, Python, PCRE and most engines. Named groups or lookbehind, not used in these patterns, are the usual portability gotchas.
- Why does the IPv4 pattern look so much longer than \d+\.\d+\.\d+\.\d+?
- A pattern that simply matches digits and dots would also accept invalid addresses like 999.999.999.999 — constraining each octet to 0-255 requires the longer alternation shown here.