@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
- Yarn
- pnpm
npm install --save-dev @babel/plugin-transform-unicode-regex
yarn add --dev @babel/plugin-transform-unicode-regex
pnpm add --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"],
});