Regex Patterns
A curated catalogue of validation patterns developers reach for repeatedly — email, URL, IPv4 and IPv6, UUID, semver, phone numbers, postal codes, credit cards, IBAN, JWT, base64, hex colours, dates, file paths, locale tags — each with the pattern itself, an example match, an example non-match, and a citation to the source the pattern is based on.
Quick fetch
Stable URL. CORS-enabled. No auth.
curl https://staticdata.dev/v1/regex-patterns.json
Or use as a typed import:
import { regexPatterns } from "https://staticdata.dev/v1/regex-patterns.ts"
Formats
- JSON 24.5 KB
/v1/regex-patterns.json
min: 20.9 KB · /v1/regex-patterns.min.json
- CSV 14.5 KB
/v1/regex-patterns.csv
- TypeScript 24.7 KB
/v1/regex-patterns.ts
export const regexPatterns
type RegexPattern = (typeof regexPatterns)[number]
Schema
Each record in the dataset has the following shape.
| Field | Type | Description | Example |
|---|---|---|---|
| id | string | Stable identifier (kebab-case) | |
| name | string | Human-readable name | Email address (RFC 5322 simplified) |
| pattern | string | The regex source string (no anchors stripped) | |
| description | string | What the pattern matches and any caveats | Matches a typical email address. |
| example | string | A string the pattern matches | jane.doe@example.com |
| nonExample | string | A string the pattern does not match | jane.doe@example |
| source | string | URL or specification the pattern is derived from | https://www.regular-expressions.info/email.html |
Preview
First 10 records.
| id | name | pattern | description | example | nonExample |
|---|---|---|---|---|---|
| Email address (RFC 5322 simplified) | ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ | Matches a typical email address (the regular-expressions.info pattern with lowercase letters added). Not RFC 5322 compliant: it accepts some invalid addresses (e.g. consecutive dots) and rejects some valid ones, but is sufficient for most input validation. | jane.doe@example.com | jane.doe@example | |
| email-strict | Email address (HTML5 input[type=email]) | ^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$ | The WHATWG HTML valid e-mail address pattern used by input[type=email]. Deliberately looser than RFC 5322 in the local part (e.g. consecutive dots are allowed) and requires no TLD. | a.b+c@example.co.uk | a.b@example..com |
| url | HTTP/HTTPS URL | ^https?://[^\s/$.?#].[^\s]*$ | Matches an http:// or https:// URL. | https://example.com/path?q=1 | ftp://example.com |
| url-strict | URL (full RFC 3986 scheme set) | ^[a-zA-Z][a-zA-Z\d+\-.]*:[^\s]+$ | Matches an absolute URI: an RFC 3986-valid scheme followed by a colon and non-whitespace characters. Does not validate the rest of the URI. | mailto:user@example.com | ://example |
| ipv4 | IPv4 address | ^((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 a dotted-quad IPv4 address with 0-255 octets. | 192.168.1.1 | 256.0.0.1 |
| ipv6 | IPv6 address | ^(([0-9a-fA-F]{1,4}:){7,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 the canonical IPv6 address forms (full, shortened, and ::). | 2001:db8::1 | 2001:zz::1 |
| mac-address | MAC address (EUI-48) | ^([0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}$ | Matches a MAC address with colon or hyphen separators. | 01:23:45:67:89:AB | 01-23-45-67-89 |
| uuid-v4 | UUID v4 | ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$ | Matches a UUID v4 (random, with version and variant bits). | f47ac10b-58cc-4372-a567-0e02b2c3d479 | f47ac10b-58cc-3372-a567-0e02b2c3d479 |
| uuid-any | UUID (any version) | ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$ | Matches a UUID of any version 1-8. | 01890dfd-c0d6-7c0a-bc6e-7b9b6c4a7e17 | not-a-uuid |
| hex-color | Hex color (#RGB / #RRGGBB / #RRGGBBAA) | ^#([0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$ | Matches a 3-, 4-, 6-, or 8-digit hex color. | #1a1a19 | #xyzxyz |
Fetch examples
Drop-in snippets in five languages.
curl -sSL https://staticdata.dev/v1/regex-patterns.json | jq '.[0]' import type { RegexPattern } from "https://staticdata.dev/v1/regex-patterns.ts";
const res = await fetch("https://staticdata.dev/v1/regex-patterns.min.json");
if (!res.ok) throw new Error(`Fetch failed: ${res.status}`);
const regexPatterns: RegexPattern[] = await res.json();
console.log(regexPatterns[0]); import urllib.request, json
with urllib.request.urlopen("https://staticdata.dev/v1/regex-patterns.min.json") as r:
regexPatterns = json.load(r)
print(regexPatterns[0]) package main
import (
"encoding/json"
"fmt"
"net/http"
)
func main() {
resp, err := http.Get("https://staticdata.dev/v1/regex-patterns.min.json")
if err != nil { panic(err) }
defer resp.Body.Close()
var data []map[string]any
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
panic(err)
}
fmt.Println(data[0])
} use serde_json::Value;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let body = ureq::get("https://staticdata.dev/v1/regex-patterns.min.json").call()?.into_string()?;
let data: Vec<Value> = serde_json::from_str(&body)?;
println!("{:?}", data.first());
Ok(())
} Sources and methodology
Regex validation is famously imperfect. The patterns here are pragmatic: they reject the most common malformed inputs without trying to fully implement the underlying spec. For email and URL in particular, prefer real parsers when correctness matters — these patterns are for input-time UX hints, not security boundaries.
Where a pattern depends on regex engine features:
- Unicode mode (
uflag): required forunicode-letter,emoji. The dataset stores the pattern as the source string; you must apply the flag yourself. - Lookahead:
hostname,password-strong,ssn-usandnon-emptyuse lookaheads. PCRE, ECMAScript, .NET, Java and Pythonresupport them; RE2 (Go, and Rust’sregexcrate) does not. - Backreferences: none of the patterns use backreferences.
The pattern field is the bare regex source, written for ECMAScript (JavaScript) syntax and tested against each record’s example and nonExample: anchors (^…$) are included where the pattern is intended to match the full string. Strip them if you want to use the pattern in a match-anywhere fashion.
The nonExample is one example of a string that does not match — useful for testing your validation paths.
Versioning
URLs under /v1/ are stable: field names and types will not change in a way
that breaks consumers. Values can be corrected or records added when the upstream source
changes; schema-incompatible updates ship under a new version path. See the
regex-patterns changelog for this dataset's history.
More Code datasets
- ansi-colors
- ascii
- cron-presets
- css-at-rules
- css-functions
- css-named-colors
- css-properties
- css-pseudo-classes
- css-pseudo-elements
- css-units
- data-units
- exit-codes
- file-signatures
- hash-algorithms
- js-array-methods
- js-math-methods
- js-object-methods
- js-string-methods
- json-schema-keywords
- jwt-claims
- mathematical-constants
- measurement-units
- node-builtin-modules
- owasp-top-10
- periodic-table
- physical-constants
- posix-signals
- programming-languages
- regex-flags
- roman-numerals
- si-base-units
- si-derived-units
- si-prefixes
- spdx-licenses
- strftime-tokens
- tailwind-colors
- time-units
- unicode-blocks
- unicode-general-categories
- unicode-planes
- unix-file-permissions
- xterm-256-colors