【文件属性】:
文件名称:nth-match:查找正则表达式的第 n 个可能匹配项
文件大小:3KB
文件格式:ZIP
更新时间:2021-06-26 03:02:08
JavaScript
第 n 场比赛
安装
npm install nth-match
用法
var nthMatch = require ( 'nth-match' ) ;
var source = 'hello world' ;
var match = nthMatch ( source , / \w { 2 } / , 3 ) ;
console . log ( match )
// > 'lo'
为什么不直接使用/g修饰符?
您可以将上面的示例重写为:
var matches = / \w { 2 } / g ;
console . log ( matches [ 3 ] ) ;
但这会产生略有不同的结果。 nth-match允许nth-match重叠:
['he', 'el', 'll', 'lo']
而使用/g修饰符给出:
['he', 'll', 'wo', 'rl']
执照
【文件预览】:
nth-match-master
----.travis.yml(36B)
----index.js(674B)
----test.js(360B)
----package.json(549B)
----LICENSE(1KB)
----.gitignore(15B)
----README.md(683B)