Error in user YAML: (<unknown>): found character that cannot start any token while scanning for the next token at line 2 column 8
---
id: babel-plugin-proposal-duplicated-named-capturing-groups-regex
title: @babel/plugin-proposal-duplicated-named-capturing-groups-regex
sidebar_label: duplicated-named-capturing-groups-regex
---
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);
npm install --save-dev @babel/plugin-proposal-duplicated-named-capturing-groups-regex
{
"plugins": ["@babel/plugin-proposal-duplicated-named-capturing-groups-regex"]
}
babel --plugins @babel/plugin-proposal-duplicated-named-capturing-groups-regex script.js
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-proposal-duplicated-named-capturing-groups-regex"],
});
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