RegJSParser is a JavaScript library designed for parsing JavaScript regular expressions into an abstract syntax tree (AST). It provides a programmatic way to analyze and manipulate regular expression patterns, enabling tools that need to understand the structure of regular expressions. The current stable version is 0.13.1, with recent releases indicating an active maintenance schedule, primarily focused on dependency updates, performance improvements, bug fixes, and keeping up with the latest Unicode specifications (e.g., Unicode 17.0.0 in v0.13.0). Key differentiators include its ability to parse various modern RegExp features, such as Unicode property escapes, named capture groups, and lookbehind assertions, which are often toggled via an options object during parsing. It ships with TypeScript types, facilitating its integration into modern TypeScript projects.
npm install regjsparserVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic and advanced parsing of regular expressions, including enabling opt-in features like Unicode property escapes, named groups, and lookbehind assertions, and parsing with flags.
Always pass an options object to `parse(pattern, flags, { unicodePropertyEscape: true, namedGroups: true, lookbehind: true })` if you intend to use these features. Refer to the documentation for specific version compatibility of each option.Review your regular expressions, especially those using Unicode property escapes (e.g., `\p{Script=...}`), after upgrading major or minor versions that include Unicode updates (e.g., v0.11.0 to Unicode 15.1.0/16.0.0, v0.13.0 to Unicode 17.0.0).Thoroughly test existing regular expressions after upgrading to `v0.11.0` or later, particularly those using anchors (`^`, `$`) with quantifiers or intricate lookbehind constructs in Unicode mode. Consult the changelog for details on specific affected patterns.
Ensure the `namedGroups: true` option is passed to the `parse` function: `parse(pattern, flags, { namedGroups: true });`Enable Unicode property escapes by passing `unicodePropertyEscape: true` to the options object: `parse(pattern, flags, { unicodePropertyEscape: true });`For CommonJS, use `const { parse } = require('regjsparser');` or `const parse = require('regjsparser').parse;`. Ensure you are accessing the `parse` property from the module export.No dependency data recorded yet.