Get index of each capture in a JavaScript regex
by matousac
JavaScript
let re = /(a).(b)(c.)d/d
let str = "aabccde"
let match = str.match(re)
console.log(match.indices) // [[0, 6], [0, 1], [2, 3], [3, 5]]
re = /(a).(.)/d
str = "aaa"
match = str.match(re)
console.log(match.indices) // [[0, 3], [0, 1], [2, 3]]