@babel/plugin-transform-named-capturing-groups-regex
信息
This plugin is included in @babel/preset-env
, in ES2018
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
).
This plugin transforms regular expression literals to support named capturing groups. It does not patch the new RegExp
constructor, since its arguments cannot be pre-transformed statically: to handle runtime behavior of functions/classes, you will need to use a polyfill instead.
Examples
In
JavaScript
var re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/;
console.log(re.exec("1999-02-29").groups.year);
Out
JavaScript
var re = _wrapRegExp(/(\d{4})-(\d{2})-(\d{2})/, { year: 1, month: 2, day: 3 });
console.log(re.exec("1999-02-29").groups.year);