Someone can explain to me while this piece of code doesn't find all the occurrences?
var re = /000/g;
var str = "000000"
while ((match = re.exec(str)) != null) {
console.log("match found at " + match.index);
}
it prints
match found at 0
match found at 3
but it's not true. Matches should be at indexes 0, 1, 2, 3!