Regexp match indices
d
フラグを付けて正規表現で検索した場合に、マッチした位置を indices
から得られるようになった。
Example
const text = "abc-abc*abc/abc";
const regex = /(?<text>abc)/dg;
for (match of text.matchAll(regex)) {
console.log(match);
// { indices: { groups: { text: [0,4] } } }
// { indices: { groups: { text: [4,7] } } }
// { indices: { groups: { text: [8,11] } } }
// { indices: { groups: { text: [12,15] } } }
}
Link
最終更新