1.0.0 • Published 9 years ago

nth-match v1.0.0

Weekly downloads
7
License
MIT
Repository
github
Last release
9 years ago

nth-match

Build Status

Install

npm install nth-match

Usage

var nthMatch = require('nth-match');
var source = 'hello world';
var match = nthMatch(source, /\w{2}/, 3);

console.log(match)
// > 'lo'

Why not just use the /g modifier?

You might rewrite the example above as:

var matches = /\w{2}/g;
console.log(matches[3]);

but this will give slightly different results. nth-match allows overlaps in matches:

['he', 'el', 'll', 'lo']

whereas using the /g modifier gives:

['he', 'll', 'wo', 'rl']

License

MIT