regexp.execall

1.0.2 • Public • Published

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

Package Sidebar

Install

npm i regexp.execall

Weekly Downloads

375

Version

1.0.2

License

MIT

Last publish

Collaborators

  • eush77