{"library":"regexp-tree","title":"RegExp Tree: Regular Expression Processor","description":"regexp-tree is a JavaScript library designed for comprehensive processing of regular expressions. It provides a full suite of APIs including a parser that generates an Abstract Syntax Tree (AST) based on the ECMAScript regular expression grammar, tools for AST traversal and transformation, an optimizer, and an interpreter. It also features a compatibility transpiler and supports custom regular expression extensions. Currently stable at version 0.1.27, it appears to be actively maintained, though release cadence isn't explicitly stated. Its key differentiators include its extensive set of processing capabilities beyond simple parsing, offering deep inspection, modification, and optimization of regular expressions. The library also ships with TypeScript type definitions, enhancing developer experience for TypeScript users.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install regexp-tree"],"cli":null},"imports":["import * as regexpTree from 'regexp-tree';","const regexpTree = require('regexp-tree');","import type { AST } from 'regexp-tree';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import * as regexpTree from 'regexp-tree';\n\n// Example: Parse, transform, and optimize a regular expression\nconst regexString = '/a[bc]d|efg+/gi';\n\ntry {\n  // 1. Parse the regular expression to get its AST\n  const ast = regexpTree.parse(regexString);\n  console.log('Original AST (partial):', JSON.stringify(ast, null, 2).substring(0, 100) + '...');\n\n  // 2. Transform the AST (e.g., replace a character)\n  const transformedAst = regexpTree.transform(regexString, {\n    char(path) {\n      if (path.node.value === 'b') {\n        path.node.value = 'x'; // Change 'b' to 'x'\n      }\n    }\n  });\n  console.log('Transformed Regexp:', transformedAst.toString()); // Outputs transformed regex string\n\n  // 3. Optimize the regular expression\n  const optimizedAst = regexpTree.optimize(regexString);\n  console.log('Optimized Regexp:', optimizedAst.toString());\n\n} catch (error) {\n  if (error instanceof Error) {\n    console.error('Error processing regex:', error.message);\n  } else {\n    console.error('An unknown error occurred:', error);\n  }\n}","lang":"typescript","description":"Demonstrates parsing a regular expression into an Abstract Syntax Tree (AST), then applying a custom transformation to modify a character, and finally optimizing the regex for improved performance or conciseness.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}