webdev_regex_tester
Test JavaScript regular expressions against sample text to find matches, capture groups, and preview find-and-replace results. Validate patterns safely without executing code.
Instructions
Regular Expression Tester (Match / Replace). Test a JavaScript-flavoured regular expression against sample text, returning every match with its position and capture groups, and optionally a regex find-and-replace preview. Set the flags object to toggle global, ignoreCase, multiline, and dotAll behaviour; supply replacement to also get the replaced string. Safe by design - it compiles and runs the pattern on the text you provide only, executes no arbitrary code, reaches no network, database, or filesystem, and is rate-limited (60 requests/minute for anonymous callers). Use this to debug or validate a pattern and inspect groups; use text_find_replace for plain text substitution without regex internals. Returns matches (text, index, end, captures), a replaceResult string, a pattern analysis summary, the resolved flag string, and an error message on invalid patterns.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pattern | Yes | The regular expression body without slashes or inline flags (for example a digit-class pattern). Must not be blank; an invalid pattern returns an error field instead of throwing. | |
| testString | Yes | The sample text the pattern is run against. Must not be blank. Also accepted under the legacy key text. | |
| flags | No | Optional regex flag toggles assembled into a flag string. Omitted flags use their defaults. | |
| replacement | No | Optional replacement string for a find-and-replace preview (supports dollar-1 and named backreferences). When blank, replaceResult is empty. Also accepted under the legacy key replacePattern. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| success | No | True when the pattern compiled and ran without error. | |
| pattern | No | The submitted regex pattern, echoed back. | |
| text | No | The submitted test string, echoed back. | |
| flags | No | The resolved flag string built from the flags object (for example gi). | |
| flagOptions | No | The effective flag toggles after defaults were applied. | |
| replacement | No | The submitted replacement string, echoed back. | |
| matches | No | One entry per match (or a single entry when global is false). | |
| replaceResult | No | The text after applying replacement, or empty when no replacement was given. | |
| patternAnalysis | No | Structural summary of the pattern, or null when the pattern or text was empty. | |
| error | No | Null on success; an invalid-regex-pattern message when compilation failed. |