How to use the exec function from xregexp
Find comprehensive JavaScript xregexp.exec code examples handpicked from public code repositorys.
17 18 19 20 21 22 23 24 25 26
var date = XRegExp('(?<year> [0-9]{4} ) -? # year \n\ (?<month> [0-9]{2} ) -? # month \n\ (?<day> [0-9]{2} ) # day ', 'x'); // XRegExp.exec gives you named backreferences on the match result var match = XRegExp.exec('2012-02-22', date); match.year; // -> '2012' // It also includes optional pos and sticky arguments var pos = 3, result = [];
+ 3 other calls in file
23 24 25 26 27 28 29 30 31 32
match.year; // -> '2017' // It also includes optional pos and sticky arguments let pos = 3; const result = []; while (match = XRegExp.exec('<1><2><3>4<5>', /<(\d+)>/, pos, 'sticky')) { result.push(match[1]); pos = match.index + match[0].length; } // result -> ['2', '3']
+ 3 other calls in file
24 25 26 27 28 29 30 31 32
```js // Change this const name = XRegExp.exec(str, regexWithNamedCapture).name; // To this const name = XRegExp.exec(str, regexWithNamedCapture).groups.name; ``` See below for more examples of using named capture with `XRegExp.exec` and `XRegExp.replace`.
+ 7 other calls in file
GitHub: nikhilkalige/docblockr

21 22 23 24 25 26 27 28 29 30
const r = '^\\s*@(?P<fnType>(mixin|function))\\s+' + '(?P<name>' + this.settings.fnIdentifier + ')' + '\\s*(?:\\(\\s*(?P<args>.*?)\\)|{)'; const regex = xregexp(r); const matches = xregexp.exec(line, regex); if (matches === null) { return null; } return [ matches.name,
+ 5 other calls in file
3 4 5 6 7 8 9 10 11 12
var date = XRegExp(`(?<year> \\d{4} ) -? # year (?<month> \\d{2} ) -? # month (?<day> \\d{2} ) # day `, 'x'); // XRegExp.exec gives you named backreferences on the match result var match = XRegExp.exec('2015-02-22', date); console.log(match); // -> [ '2015-02-22', '2015', '02', '22', index: 0, input: '2015-02-22', // year: '2015', month: '02', day: '22' ] // XRegExp.replace allows named backreferences in replacements
+ 3 other calls in file
GitHub: mozilla-raptor/test

47 48 49 50 51 52 53 54 55 56
let message = {}; let regex = PATTERNS[type]; try { let match = xRegExp.exec(stripped, regex); let captureNames = regex.xregexp.captureNames; R.forEach(field => { if (captureNames.indexOf(field) >= 0) {
xregexp.exec is the most popular function in xregexp (52 examples)