A Babel plugin that transpiles Regex+ template tag (`regex`…``) calls into native RegExp literals at build time. Current stable version is 6.1.0, updated January 2025. Releases are tied to the base Regex+ library. Key differentiators: eliminates runtime dependency, zero runtime cost, supports modern regex features (atomic groups, subroutines, definition groups, Unicode sets). Designed for Node.js and browser bundlers using Babel.
npm install babel-plugin-transform-regexVerified import paths — ran on the pinned version, not inferred.
Demonstrates setting up the Babel plugin and transforming a Regex+ template to a native RegExp literal with flag v.
Ensure target environments support flag v or use option `disableUnicodeSets: true` to fall back to flag u.
Use `disableUnicodeSets: true` if you need to avoid flag v in the output.
Ensure all interpolated values are inline literals (strings, numbers, regexes) or `pattern` tags. Otherwise, the `regex` call remains at runtime.
Test output thoroughly when using `optimize`. Consider not using it for complex patterns.
Install `regex` as a dependency: npm install regex
Run: npm install --save-dev babel-plugin-transform-regex
Use Babel's @babel/plugin-transform-unicode-sets-regex or set `disableUnicodeSets: true` in plugin options.