Capabilities
The package parses regex patterns and substitution strings. It uses separate syntax rules and validation for each flavor.
Flavor support
Both parser functions support these flavors:
| Flavor | API value |
|---|---|
| PCRE2 | Flavors.PCRE2 |
| PCRE | Flavors.PCRE |
| JavaScript | Flavors.JAVASCRIPT |
| Python | Flavors.PYTHON |
| Go | Flavors.GOLANG |
| Java | Flavors.JAVA |
| .NET | Flavors.DOTNET |
| Rust | Flavors.RUST |
| POSIX ERE | Flavors.POSIX_ERE |
| POSIX BRE | Flavors.POSIX_BRE |
Syntax coverage
The parser handles the constructs that the selected flavor supports. Coverage includes:
- Capturing groups, named groups, and backreferences
- Alternation, quantifiers, atomic groups, and possessive quantifiers
- Lookaheads, lookbehinds, and flavor-specific width validation
- Subroutine calls, conditional expressions, verbs, and callouts
- Character classes, intersections, subtraction, and POSIX classes
- Inline modifiers, comments, anchors, and quoted literals
- Unicode escapes, Unicode properties, and flavor-specific Unicode modes
- Numeric, named, and special insertions in substitution strings
Output and metadata
- A typed token tree based on discriminated TypeScript unions
- Start and end positions for each token
- Typed error codes on invalid tokens
- Partial token output after a syntax error
- Parent, previous-token, related-token, and reference relationships
- Exact, minimum, and maximum match-width metadata
- Parser state for groups, flags, Unicode modes, and flavor features
Public helpers
getFlavorFlagDefinitionandvalidateFlagsfor flavor flags- Type guards for groups and lookarounds
getTokenMarkerandresolveRepresentativeTokenfor editor highlightinggetLineTerminatorCodePointsandgetCharCodefor character dataisBacktrackingFlavorfor engine classification
Scope
The package parses and validates syntax. It does not execute patterns, apply substitutions, lint style, or assess ReDoS risk.
The target regex engine remains the source of truth for runtime matching behavior.