1.0.2 • Published 10 years ago

regexp.execall v1.0.2

Weekly downloads
53
License
MIT
Repository
github
Last release
10 years ago

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