Babel 中文文档
  • 印记中文
  • 文档
  • 配置
  • 试用
  • 视频
  • 博客
  • 赞助
  • 团队
  • GitHub
Edit

@babel/plugin-proposal-duplicated-named-capturing-groups-regex

Examples

In

var re = /(?<year>\d{4})-(?<month>\d{2})|(?<month>\d{2})-(?<year>\d{4})/;

console.log(re.exec("02-1999").groups.year);

Out

var re = _wrapRegExp(/(\d{4})-(\d{2})|(\d{2})-(\d{4})/, {
  year: [1, 4],
  month: [2, 3],
});

console.log(re.exec("02-1999").groups.year);

Installation

npm install --save-dev @babel/plugin-proposal-duplicated-named-capturing-groups-regex

Usage

With a configuration file (Recommended)

{
  "plugins": ["@babel/plugin-proposal-duplicated-named-capturing-groups-regex"]
}

Via CLI

babel --plugins @babel/plugin-proposal-duplicated-named-capturing-groups-regex script.js

Via Node API

require("@babel/core").transformSync("code", {
  plugins: ["@babel/plugin-proposal-duplicated-named-capturing-groups-regex"],
});

Options

runtime

boolean, defaults to true

When this option is disabled, Babel doesn't wrap RegExps with the _wrapRegExp helper. The output only supports internal group references, and not runtime properties:

var stringRe = /(?:(?<quote>")|(?<quote>')).*?\k<quote>/;

stringRe.test("'foo'"); // "true", works
stringRe.exec("'foo'").groups.quote; // undefined

You can read more about configuring plugin options here

  • Examples
  • Installation
  • Usage
    • With a configuration file (Recommended)
    • Via CLI
    • Via Node API
  • Options
    • runtime
Babel 中文文档
文档
学习 ES2015
社区
视频用户Stack OverflowSlack 频道Twitter
更多
博客GitHub 组织GitHub 仓库Website 仓库旧版网址 6.x旧版网址 5.x