Skip to main content

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:

FlavorAPI value
PCRE2Flavors.PCRE2
PCREFlavors.PCRE
JavaScriptFlavors.JAVASCRIPT
PythonFlavors.PYTHON
GoFlavors.GOLANG
JavaFlavors.JAVA
.NETFlavors.DOTNET
RustFlavors.RUST
POSIX EREFlavors.POSIX_ERE
POSIX BREFlavors.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

  • getFlavorFlagDefinition and validateFlags for flavor flags
  • Type guards for groups and lookarounds
  • getTokenMarker and resolveRepresentativeToken for editor highlighting
  • getLineTerminatorCodePoints and getCharCode for character data
  • isBacktrackingFlavor for 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.