Regex

POST/v0/regex

Validates a regular expression pattern. Checks whether the pattern compiles successfully with the given flags. Returns the list of named capture groups found in the pattern.

Request Body (JSON)

FieldTypeRequiredDescription
patternstringYesThe regular expression pattern to validate
flagsstringNoRegex flags (e.g. gi, ms). Valid flags: d, g, i, m, s, u, v, y

Example Request

curl -X POST https://api.isvalid.dev/v0/regex \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"pattern": "^(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})$", "flags": "i"}'

Response Fields

FieldTypeDescription
validbooleanWhether the pattern is a valid regular expression
patternstringThe pattern as provided
flagsstring | nullThe flags used for validation
namedGroupsstring[]List of named capture groups found in the pattern
errorstringError message when the pattern is invalid (only present when valid is false)

Example Response — valid

{
  "valid": true,
  "pattern": "^(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})$",
  "flags": "i",
  "namedGroups": ["year", "month", "day"]
}

Example Response — invalid

{
  "valid": false,
  "error": "Invalid regular expression: /[/: Unterminated character class"
}