nth-match

1.0.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i nth-match

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • joshwnj