{"library":"regex-parser","title":"Regular Expression String Parser","description":"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.","language":"javascript","status":"maintenance","last_verified":"Thu Apr 23","install":{"commands":["npm install regex-parser"],"cli":null},"imports":["import RegexParser from 'regex-parser';","const RegexParser = require('regex-parser');","import type RegexParser from 'regex-parser';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import RegexParser from 'regex-parser';\n\n// Example 1: Basic parsing\nconst regexString1 = \"/^hello world$/i\";\nconst parsedRegex1 = RegexParser(regexString1);\nconsole.log(`Parsed regex 1: ${parsedRegex1}`);\nconsole.log(`Type: ${parsedRegex1.constructor.name}`);\nconsole.log(`Flags: ${parsedRegex1.flags}`);\n\n// Example 2: Regex with global flag\nconst regexString2 = \"/search/g\";\nconst parsedRegex2 = RegexParser(regexString2);\nconsole.log(`Parsed regex 2: ${parsedRegex2}`);\nconsole.log(`Test 'searchable': ${parsedRegex2.test('searchable')}`);\n\n// Example 3: Invalid flags (graceful handling since v2.3.0)\nconst regexString3 = \"/pattern/xyz\";\nconst parsedRegex3 = RegexParser(regexString3);\nconsole.log(`Parsed regex 3 with invalid flags: ${parsedRegex3}`);\n// Note: Invalid flags will typically be ignored, resulting in a RegExp without those flags.\n\n// Example 4: Parsing a string that is not a regex literal\n// The parser expects a regex literal string, e.g., '/pattern/flags'.\n// If a plain string is provided, it might be interpreted as a pattern without flags.\nconst plainString = \"just some text\";\nconst parsedPlain = RegexParser(plainString);\nconsole.log(`Parsed plain string: ${parsedPlain}`);\nconsole.log(`Test 'just some text': ${parsedPlain.test('just some text')}`);","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}