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, immutable 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 23.4 KB
/v1/regex-patterns.json
min: 19.7 KB · /v1/regex-patterns.min.json
- CSV 13.4 KB
/v1/regex-patterns.csv
- TypeScript 23.6 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 | [email protected] |
| nonExample | string | A string the pattern does not match | jane.doe@example |
| source | string | URL or specification the pattern is derived from | https://emailregex.com |
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. Not RFC 5322 fully compliant; sufficient for most validation use cases. | [email protected] | 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])?)*$ | Matches the WHATWG HTML5 specification for input[type=email]. | [email protected] | [email protected] |
| 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 a URL with any RFC 3986 valid scheme. | mailto:[email protected] | ://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. - Lookaround: several patterns use lookaheads. All modern engines (PCRE, ECMAScript, RE2 with limitations, .NET, Python
re) support them. - Backreferences: none of the patterns use backreferences.
The pattern field is the bare regex source: 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 immutable. The data they return will not change in a way
that breaks consumers. Schema-incompatible updates ship under a new version path. See the
regex-patterns changelog for this dataset's history.