Is there a way to retrieve the (starting) character positions inside a string of the results of a regex match() in Javascript?
exec returns an object with a index property:
exec
index
var match = /bar/.exec("foobar"); if (match) { console.log("match found at " + match.index); }
2.1m questions
2.1m answers
60 comments
57.0k users