Parser capabilities
The package parses regex patterns and substitution strings. Syntax rules and validation depend on the selected flavor.
Flavor support
Both parser functions accept these flavors. The table lists parser flavors, not matching-engine versions.
| Flavor | Exported value | String identifier |
|---|---|---|
| PCRE2 | Flavors.PCRE2 | pcre2 |
| PCRE | Flavors.PCRE | pcre |
| JavaScript | Flavors.JAVASCRIPT | javascript |
| Python | Flavors.PYTHON | python |
| Go | Flavors.GOLANG | golang |
| Java | Flavors.JAVA | java |
| .NET | Flavors.DOTNET | dotnet |
| Rust | Flavors.RUST | rust |
| POSIX ERE | Flavors.POSIX_ERE | posix_ere |
| POSIX BRE | Flavors.POSIX_BRE | posix_bre |
Syntax coverage
The parser recognizes these constructs when the selected flavor supports them:
- 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.
Verify matching behavior in your target regex engine.