Return positions of a regex match() in Javascript? Return positions of a regex match() in Javascript? javascript javascript

Return positions of a regex match() in Javascript?


exec returns an object with a index property:

var match = /bar/.exec("foobar");if (match) {    console.log("match found at " + match.index);}