📌  相关文章
📜  javascript 查找字符串中的所有匹配项 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:43.043000             🧑  作者: Mango

代码示例1
var str = "I learned to play the Ukulele in Lebanon."
var regex = /le/gi, result, indices = [];
while ( (result = regex.exec(str)) ) {
    indices.push(result.index);
}
console.log(indices) // => [2, 25, 27, 33]
//find all occurence of le and return the return an array of the indeces