Explain a Regex
explain_regexParse a regex into a syntax tree and get a plain-English explanation of what it matches. Verify a pattern does what you intend before shipping it.
Instructions
Parse a regular expression into a real syntax tree and describe in plain English what it matches. Use this to sanity-check a regex you (or someone else) wrote actually does what you intended, before shipping it.
Args:
pattern (string, 1-1000 chars): the regex source, without delimiters (no leading/trailing "/").
Returns: For JSON format: { "explanation": string, "parsed": boolean, "error": string | null } explanation is empty and error is set if the pattern could not be parsed (e.g. unbalanced parentheses, unsupported syntax).
Examples:
Use when: "does this regex actually require the string to start with a letter?" -> pass the pattern, read the explanation
Don't use when: you need to actually run the regex against text -- this tool never executes the pattern, only analyzes its source
Error Handling:
Returns an error (not an exception) if the pattern doesn't parse, with the parser's best guess at where the problem is.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pattern | Yes | The regex source, without the surrounding slashes, e.g. "^[a-z0-9_]{3,16}$". |