Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

regexp.execall

eush774.8kMIT1.0.2

Array of RegExp.prototype.exec results

regex, regexp, re, regular, expression, exec, match, matches, execall, all, find, findall, immutable, string, str, multiple, many, global

readme

regexp.execall Build Status Dependency Status

npm

Applies RegExp.prototype.exec iteratively. Returns array of matches.

No fancy custom return format to learn.

Example

var execAll = require('regexp.execall');

execAll(/\w+/g, 'foo bar')
//=> [ [ 'foo', index: 0, input: 'foo bar' ],
//     [ 'bar', index: 4, input: 'foo bar' ] ]

Subgroups are handled just as you expect:

execAll(/\$(\d+)/g, '$200 and $400')
//=> [ [ '$200', '200', index: 0, input: '$200 and $400' ],
//     [ '$400', '400', index: 9, input: '$200 and $400' ] ]

API

execAll(regexp, string)

Returns array of matches in the exact format of RegExp.prototype.exec. If regexp is non-global, the resulting array contains either one or zero elements.

It is basically equivalent to the following snippet:

var matches = [], match;

while ((match = regexp.exec(string)) != null) {
  matches.push(match);
}

Install

npm install regexp.execall

License

MIT