Home → JSON to RegEx Generator
Generate regular expression patterns from your JSON structure and values.
Generate regular expression patterns from your JSON structure and values. This tool runs entirely in your browser — no data is ever sent to a server. Free to use, no account required.
The regex generator creates regular expression patterns for validating JSON string fields, saving time compared to writing patterns from scratch.
Provide example valid values and the tool infers a regex pattern that matches all of them. For example, provide several phone number examples and the tool generates a pattern that validates that format.
A library of ready-made patterns covers the most common validation needs: email address, URL, ISO 8601 date, UUID, IPv4 address, credit card number, zip code, and hex color code.
Generated patterns integrate directly into JSON Schema validation via the pattern keyword.
Add "pattern": "your-regex-here" to any string type field in your JSON Schema. The value must match the regex (using ECMA 262 dialect) for the schema validation to pass. The pattern must match the complete string, not just a substring.
Always test regex patterns against both valid examples (which should match) and invalid examples (which should not) before deploying. Edge cases like empty strings, unicode characters, and boundary values often reveal pattern issues.
Copy these tested regex patterns directly into your JSON Schema pattern keyword. All patterns use ECMA 262 regex dialect, compatible with JSON Schema validators and JavaScript.
| Field Type | Pattern | Example valid value |
|---|---|---|
| Email address | ^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$ | alice@example.com |
| UUID v4 | ^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$ | 550e8400-e29b-41d4-a716-446655440000 |
| ISO 8601 date | ^\d{4}-\d{2}-\d{2}$ | 2026-03-21 |
| ISO 8601 datetime | ^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+\-]\d{2}:\d{2})$ | 2026-03-21T14:30:00Z |
| URL (http/https) | ^https?:\/\/[\w\-]+(\.[\w\-]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-@?^=%&&/~\+#])?$ | https://example.com/path |
| IPv4 address | ^(\d{1,3}\.){3}\d{1,3}$ | 192.168.1.1 |
| Hex color code | ^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$ | #FF5733 |
| Semantic version | ^\d+\.\d+\.\d+$ | 1.2.34 |
| Slug (URL-safe) | ^[a-z0-9]+(?:-[a-z0-9]+)*$ | my-product-name |
| Phone (E.164) | ^\+[1-9]\d{1,14}$ | +14155552671 |
| Credit card (basic) | ^\d{13,19}$ | 4111111111111111 |
| Base64 encoded | ^[A-Za-z0-9+/]+={0,2}$ | SGVsbG8gV29ybGQ= |
Here is a real-world JSON Schema that uses pattern to validate multiple fields in a user registration object. Copy and adapt it for your own API.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "User Registration",
"type": "object",
"required": ["email", "username", "birthDate"],
"properties": {
"email": {
"type": "string",
"pattern": "^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$",
"description": "Valid email address"
},
"username": {
"type": "string",
"pattern": "^[a-z0-9_]{3,20}$",
"description": "3-20 lowercase alphanumeric characters or underscores"
},
"birthDate": {
"type": "string",
"pattern": "^\d{4}-\d{2}-\d{2}$",
"description": "ISO 8601 date (YYYY-MM-DD)"
},
"website": {
"type": "string",
"pattern": "^https?:\/\/.+",
"description": "Optional URL starting with http or https"
},
"phoneNumber": {
"type": "string",
"pattern": "^\+[1-9]\d{1,14}$",
"description": "E.164 international phone number"
}
}
}
pattern keyword uses ECMA 262 regex (same as JavaScript). Avoid PCRE-only features like lookbehind assertions.\d{4} will match "hello1234world". Always anchor with ^ and $ to require a full match.\\d in JSON to represent the regex \d.pattern keyword only applies to values of type string. It is ignored for other types.Explore more tools: All JSON Tools | Validator | Pretty Print | JSON Diff
The table below lists ready-to-use regex patterns for the most common field types found in JSON APIs. All patterns are anchored with ^ and $ to require a full match, preventing partial matches on fields like "hello1234" satisfying a \d{4} pattern.
| Field Type | Regex Pattern | Matches |
|---|---|---|
| ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ | alice@example.com | |
| URL | ^https?://[^\s/$.?#].[^\s]*$ | https://example.com |
| UUID | ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$ | 550e8400-e29b-... |
| ISO Date | ^\d{4}-\d{2}-\d{2}$ | 2024-01-15 |
| ISO DateTime | ^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2} | 2024-01-15T10:30:00 |
| Phone (US) | ^\+?1?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$ | +1 (555) 123-4567 |
| IPv4 | ^(\d{1,3}\.){3}\d{1,3}$ | 192.168.1.1 |
| Hex color | ^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$ | #FF5733 |
JSON Schema's pattern keyword validates string values against a regex. Remember that JSON requires backslashes to be double-escaped: write \\d in the JSON string to represent the regex \d.
{
"$schema": "https://json-schema.org/draft/2020-12",
"type": "object",
"properties": {
"email": {
"type": "string",
"pattern": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"
},
"createdAt": {
"type": "string",
"pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}",
"description": "ISO 8601 datetime"
},
"userId": {
"type": "string",
"pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
}
}
}