Infer a regex from positive and negative example strings or test an existing pattern, returning a JSON report of matches, failures, syntax errors, backtracking risks and refinements.
Act as a regex generator and tester. Either infer a pattern from labeled examples or test a supplied pattern against test strings. Report results per string, and generalize from the examples instead of listing them literally. ## Inputs Mode: generate from examples, or test a supplied pattern: [MODE] Regex flavour and matching function (for example JavaScript test(), Python re.fullmatch or re.search): [FLAVOUR] Positive examples (must match): [POSITIVE_EXAMPLES] Negative examples (must not match): [NEGATIVE_EXAMPLES] Supplied pattern, if testing: [PATTERN] Description of the general rule the examples represent: [RULE] ## Instructions 1. **Pattern generation**: derive a pattern that expresses [RULE] and separates the positive and negative examples. An alternation of the literal examples (for example `hello|world|hello world`) only memorizes them; generalize unless an exact list is intended. 2. **Pattern testing**: evaluate every string with the stated matching function. Note that unanchored search can match part of a string; say whether anchors are needed. 3. **Pattern refinement**: suggest changes that improve accuracy (missed positives, accepted negatives) or efficiency. 4. **Error handling**: report syntax errors for the stated flavour and constructs that can cause catastrophic backtracking (for example nested quantifiers like `(a+)+`). 5. **Explanation**: break the pattern down part by part. 6. Add a few unlabeled edge-case strings you think could be misclassified, with your expected result. ## Return JSON with these keys: - `pattern`: the generated or tested pattern - `flags` - `matching_function` - `matches`: strings that match - `non_matches`: strings that do not match - `misclassified`: strings whose result contradicts their label - `errors`: syntax or backtracking warnings - `refinements`: suggested changes with the reason - `explanation` - `added_edge_cases`: string, expected result, reason ## Acceptance checks - Every labeled example appears in `matches` or `non_matches`, and `misclassified` is consistent with the labels. - Results are described as expected results unless the pattern was actually executed. - The pattern generalizes [RULE] rather than enumerating examples, unless an exact list was requested.
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
Mode: generate Flavour: JavaScript, RegExp.prototype.test on the whole string Positive: 1.0.0, 10.20.3, 0.1.0-alpha.1, 2.0.0-rc.2 Negative: 01.0.0, 1.0, v1.0.0, 1.0.0-, 1.2.3.4 Rule: semantic version core MAJOR.MINOR.PATCH without leading zeros, optionally followed by a hyphen and a pre-release identifier
A JSON report with a pattern such as ^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$, all four positives in matches, all five negatives in non_matches, an empty misclassified list, a refinement noting that full SemVer also allows build metadata (+...) and forbids leading zeros in numeric pre-release identifiers, and added edge cases such as 1.0.0+build.1. This pattern was executed locally against the nine labeled strings (see report); a model's answer may differ.
Ask questions or share concrete improvements.
No comments yet.
Sign in to join the discussion.
Guides for adapting and checking prompts: