Skip to content

Regex Tester

The /regex endpoint tests a regular expression pattern against a text string and returns structured match results including capture groups and named groups.

Use Cases

Validate regex patterns during development, extract structured data from raw text, debug complex capture groups, or build regex-powered search previews without running server-side code.

Parameters

ParameterRequiredDescription
patternYesThe regular expression pattern to test (max 200 characters).
textYesThe text to test the pattern against (max 1000 characters).
flagsNoRegex flags to apply. Accepted: i, m, s, u. The g flag is always applied.

Response Fields

FieldTypeDescription
validbooleantrue if the pattern is a valid regex
patternstringThe pattern as provided
flagsstringThe effective flags used (always includes g)
countnumberTotal number of matches found
matchesobject[]Array of match objects
matches[].matchstringThe full matched string
matches[].indexnumberStart index of the match in the text
matches[].groupsstring[]Array of numbered capture group values (empty string if unmatched)
matches[].namedGroupsobjectKey-value map of named capture groups ((?<name>...))

Code Examples

curl -X GET \
  "https://api.sylvain.sh/v4/regex?pattern=%5Cd%2B&text=Order+42+and+item+7"

Try It

Error Handling

Error MessageDescription
Please provide a pattern (?pattern=...)The pattern parameter is missing
Please provide a text (?text=...)The text parameter is missing
Pattern must be at most 200 charactersThe pattern exceeds the maximum length
Text must be at most 1000 charactersThe text exceeds the maximum length
Invalid flag: {flag}. Accepted flags: g, i, m, s, uOne or more flags are not supported
Invalid regular expressionThe pattern is not a valid regular expression