Babel
  • Docs
  • Setup
  • Try it out
  • Videos
  • Blog
  • Donate
  • Team
  • GitHub
Edit

@babel/plugin-transform-named-capturing-groups-regex

NOTE: This plugin generates code that needs ES6 regular expressions functionalities. If you need to support older browsers, use either the runtime: false option or import a proper polyfill (e.g. core-js).

Examples

In

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

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

Out

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

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

Installation

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

Usage

With a configuration file (Recommended)

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

Via CLI

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

Via Node API

require("@babel/core").transform("code", {
  plugins: ["@babel/plugin-transform-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>"|').*?\k<quote>/;

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

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
Docs
Learn ES2015
Community
VideosUser ShowcaseStack OverflowSlack ChannelTwitter
More
BlogGitHub OrgGitHub RepoWebsite RepoOld 6.x SiteOld 5.x Site