NOTE: this is mostly for spec-compatibility; practically regexes can be used without runtime
As the comments says, a transform can accept includeRuntime
option (which is currently disabled).
If the option is passed, regexes are wrapped into RegExpTree
wrapper, and provide extra functionality at runtime (e.g. accessing captured named groups on matched result).
The runtime implementation already exists, we need to pull it into a separate package, which can be auto-required by the transform.
const re = new RegExp(` # A regular expression for date. (?<year>\\d{4})- # year part of a date (?<month>\\d{2})- # month part of a date (?<day>\\d{2}) # day part of a date `, 'x'); const result = re.exec('2017-04-17'); console.log(result.groups.year); // 2017
Is translated into:
// Auto-require `regexp-tree-runtime`, it should be in the dependencies. const RegExpTree = require('regexp-tree-runtime'); ... const re = new RegExpTree(/(\d{4})-(\d{2})-(\d{2})/, { flags: 'x', source: <original-source>, groups: { year: 1, month: 2, day: 3, }, }); const result = re.exec('2017-04-17'); console.log(result.groups.year); // 2017
mike-marcacci, FranklinYu and jsarafajr
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4