exec
возвращает объект со свойством index
:
var match = /bar/.exec("foobar");
if (match) {
console.log("match found at " + match.index);
}
И для нескольких совпадений:
var re = /bar/g,
str = "foobarfoobar";
while ((match = re.exec(str)) != null) {
console.log("match found at " + match.index);
}