CommonJS wrapper for regex-recursion.
pnpm add regex-recursion-cjs
// CommonJS
const { recursion } = require('regex-recursion-cjs');
// Use recursion to process a regex with recursive patterns
const pattern = '\\((?:(?R=2)|[^()])\\)';
const result = recursion(pattern);
console.log(result.pattern); // Processed pattern with recursion transformed
const { recursion } = require('regex-recursion-cjs');
// Create a pattern that matches balanced parentheses
const pattern = '\\((?:(?R=10)|[^()])*\\)';
const processed = recursion(pattern);
// The processed pattern can be used with a standard RegExp
const regex = new RegExp(processed.pattern);
const text = 'foo (bar (baz) blah) end';
console.log(text.match(regex)[0]); // '(bar (baz) blah)'
const { recursion } = require('regex-recursion-cjs');
// Use named groups with recursion
const pattern = '\\((?<content>(?:\\g<content&R=2>|[^()]*)*)\\)';
const processed = recursion(pattern);
console.log(processed.pattern); // Shows the expanded pattern
# Install dependencies
pnpm install
This project uses ts-standard for linting and code formatting, which is an extension of StandardJS for TypeScript.
# Run linting
pnpm lint
# Fix linting issues automatically
pnpm lint:fix
Pre-commit hooks (using Husky and lint-staged) ensure that code is properly linted before being committed.
# Clean build artifacts
pnpm clean
# Build the package
pnpm build
# Run tests
pnpm test
# Development workflow (clean, build, test)
pnpm dev
The original regex-recursion
package is ESM-only, which can cause compatibility issues in CommonJS projects. This package provides a pre-built CommonJS version that can be used in any Node.js environment without the need for special configuration.
MIT