Skip to content

eush77/regexp.execall

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Apply RegExp.exec iteratively. Missing part of the standard RegExp interface

Resources

License

Stars

Watchers

Forks

Packages

No packages published