I\'m trying to parse the following kind of string:
[key:\"val\" key2:\"val2\"]
where there are arbitrary key:\"val\" pairs inside. I want t
Since ES9, there's now a simpler, better way of getting all the matches, together with information about the capture groups, and their index:
const string = 'Mice like to dice rice';
const regex = /.ice/gu;
for(const match of string.matchAll(regex)) {
console.log(match);
}
// ["mice", index: 0, input: "mice like to dice rice", groups: undefined]
// ["dice", index: 13, input: "mice like to dice rice", groups: undefined]
// ["rice", index: 18, input: "mice like to dice rice", groups: undefined]
It is currently supported in Chrome, Firefox, Opera. Depending on when you read this, check this link to see its current support.