Stage 5 of 8v2 · 6a450085
Classes and groups
Add classes, ranges, negation, and groups to control precedence.
Build it in your language
The tester treats your program as a black box: any language works. These are just the most convenient ones for this project.
Character Classes and Grouping
Character classes bracket allowed characters:
- Ranges:
[a-z],[A-C]. - Negation:
[^0-9](any non-digit). - Parentheses:
([A-C][^0-9])+groups multi-token subpatterns under quantifiers.
Mental Model: Per-Character Predicates
[A-C]: tests character code range .[^0-9]: inverts membership predicate.(...)+: repeats the composite group.
Your Goal in this Stage
Support character classes (ranges, negation) and grouped quantifier subexpressions.
Input Format
{
"op": "search",
"pattern": "([A-C][^0-9])+",
"text": "xxAbCz7"
}
Output Format
{
"matched": true,
"span": [2, 6]
}
Step-by-Step Implementation Guide
- Parse bracket classes: Extract ranges and negation flag.
- Parse parentheses groups: Treat inner sequence as composite atom.
- Emit output: Print JSON object.
Acceptance Criteria
- ✅ Matches character classes and ranges.
- ✅ Inverts negated classes.
- ✅ Quantifies nested parenthesized groups.
Output and errors
Multiline examples are formatted for readability. Emit compact JSON without optional spaces, with properties in the order shown by the output examples, and a final newline. Keep logs off stdout. Tests compare exact text.
Invalid inputs use stderr containing error, empty stdout, and exit 1. Valid inputs exit 0. Serialize integer results as JSON integers.