Skip to main content

babel-plugin-transform-regexp-constructors

Example

In

JavaScript
const foo = "ab+";
var a = new RegExp(foo + "c", "i");

Out

JavaScript
const foo = "ab+";
var a = /ab+c/i;

Installation

npm install babel-plugin-transform-regexp-constructors --save-dev

Usage

babel.config.json
{
"plugins": ["transform-regexp-constructors"]
}

Via CLI

Shell
babel --plugins transform-regexp-constructors script.js

Via Node API

JavaScript
require("@babel/core").transformSync("code", {
plugins: ["transform-regexp-constructors"],
});