regex-parser is a JavaScript utility module designed to parse a string representation of a regular expression and return a `RegExp` object. Its current stable version is 2.3.1. The package has seen infrequent updates, primarily focusing on documentation, license year, and the addition of TypeScript typings (since 2.2.9). It's a focused tool for environments where regular expressions are provided as strings and need to be converted to native `RegExp` objects, handling both the pattern and flags. Key differentiators include its simplicity and explicit support for parsing invalid flags gracefully (since 2.3.0). It doesn't offer complex regex manipulation or validation beyond standard JavaScript `RegExp` behavior, making it a lightweight option for this specific parsing task.
npm install regex-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to parse various string representations of regular expressions, including those with flags, and illustrates the handling of invalid flags and non-literal strings.
Ensure the input string is correctly formatted as a regex literal: `RegexParser("/my_pattern/i")` if you want flags to be parsed.For ESM/TypeScript, always use `import RegexParser from 'regex-parser';`. If you encounter type issues, ensure your `tsconfig.json` has `"esModuleInterop": true`.
Always double-check the flags in your input string to ensure they are standard `RegExp` flags (g, i, m, s, u, y, d, v). If strict validation of flags is needed, preprocess the string or check the flags of the returned `RegExp` object.
Change `const RegexParser = require('regex-parser');` or `import { RegexParser } from 'regex-parser';` to `import RegexParser from 'regex-parser';`.Switch to ESM import syntax: `import RegexParser from 'regex-parser';`.
No dependency data recorded yet.