Skip to main content

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.

FlavorExported valueString identifier
PCRE2Flavors.PCRE2pcre2
PCREFlavors.PCREpcre
JavaScriptFlavors.JAVASCRIPTjavascript
PythonFlavors.PYTHONpython
GoFlavors.GOLANGgolang
JavaFlavors.JAVAjava
.NETFlavors.DOTNETdotnet
RustFlavors.RUSTrust
POSIX EREFlavors.POSIX_EREposix_ere
POSIX BREFlavors.POSIX_BREposix_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​

  • 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.

Verify matching behavior in your target regex engine.