跳转到主要内容

@babel/plugin-transform-unicode-regex

信息

此插件包含在 @babel/preset-env

示例

输入

JavaScript
var string = "foo💩bar";
var match = string.match(/foo(.)bar/u);

输出

JavaScript
var string = "foo💩bar";
var match = string.match(
/foo((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))bar/
);

安装

npm install --save-dev @babel/plugin-transform-unicode-regex

用法

babel.config.json
{
"plugins": ["@babel/plugin-transform-unicode-regex"]
}

通过 CLI

Shell
babel --plugins @babel/plugin-transform-unicode-regex script.js

通过 Node API

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