Registry / serialization / babel-plugin-transform-regex

babel-plugin-transform-regex

JSON →
library6.1.0jsnpmunverified

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-regex
INSTALL
IMPORT
SIG · BABEL-PLUGIN-TRANS
B
babel-plugin-transform-regex
serializationjavascriptv6.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import plugin from 'babel-plugin-transform-regex'
const plugin = require('babel-plugin-transform-regex')
ESM-only with default export. CommonJS require not supported.
removeImport
// In .babelrc: { "plugins": [["babel-plugin-transform-regex", { "removeImport": true }]] }
import { removeImport } from 'babel-plugin-transform-regex'
This is a Babel plugin option, not an exported symbol. Pass via plugin options object.
regex
import { regex } from 'regex'; const r = regex`^abc$`;
import regex from 'regex'; const r = regex`^abc$`;
Regex+ exports `regex` as a named export, not default. The Babel plugin transforms these tagged template literals.

Demonstrates setting up the Babel plugin and transforming a Regex+ template to a native RegExp literal with flag v.

// Install: npm install --save-dev babel-plugin-transform-regex regex // .babelrc: { "plugins": ["babel-plugin-transform-regex"] } // source.js: import { regex } from 'regex'; const ipv4 = regex` ^ \g<byte> (\.\g<byte>){3} $ (?(DEFINE) (?<byte> 2[0-4]\d | 25[0-5] | 1\d\d | [1-9]?\d) ) `; // After Babel transform: const ipv4 = /^(?:2[0-4]\d|25[0-5]|1\d\d|[1-9]?\d)(?:\.(?:2[0-4]\d|25[0-5]|1\d\d|[1-9]?\d)){3}$/v;
Debug
Known issues
breakingv4.3.0 changed the default flag for generated regexes from u to v (unicodeSets).
fix
Ensure target environments support flag v or use option `disableUnicodeSets: true` to fall back to flag u.
affects: >=4.3.0
deprecatedOption `disableUnicodeSets` was added in v4.0.1 to replace the old behavior of always using flag u.
fix
Use `disableUnicodeSets: true` if you need to avoid flag v in the output.
affects: >=4.0.1
gotchaThe plugin only transforms static `regex` tagged templates without dynamic interpolation. Variables or complex expressions inside the template are left untransformed.
fix
Ensure all interpolated values are inline literals (strings, numbers, regexes) or `pattern` tags. Otherwise, the `regex` call remains at runtime.
affects: >=4.0.0
gotchaThe `optimize` option (experimental) uses regexp-tree optimizer which may produce incorrect results for flag-v-only syntax like nested character classes.
fix
Test output thoroughly when using `optimize`. Consider not using it for complex patterns.
affects: >=4.1.0
Errors
Common errors & fixes
Cannot find module 'regex'
Missing runtime dependency `regex` when the plugin is not used or some templates are not transformed.
fix
Install `regex` as a dependency: npm install regex
Error: [BABEL] unknown plugin 'babel-plugin-transform-regex' specified in
Plugin is not installed as a devDependency.
fix
Run: npm install --save-dev babel-plugin-transform-regex
Uncaught SyntaxError: Invalid regular expression: invalid flag v
Target environment does not support flag v (unicodeSets), but plugin outputs regexes with /v.
fix
Use Babel's @babel/plugin-transform-unicode-sets-regex or set `disableUnicodeSets: true` in plugin options.
Upgrade
Version history
6.1.0latest on npm
Audit
Dependencies
regexrequiredBase regex+ library used for transformation logic
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
babel-plugin-transform-regex — npm install babel-plugin-transform-regex · libregistry