JSFiddle - React, Tailwind, and code Playground
JavaScript
var regex = /text/g;
var text = 'this is some text and then there is some more text';
var match;
while(match = regex.exec(text)){
console.log('start index= ' +(regex.lastIndex - match[0].length));
console.log('end index= ' + (regex.lastIndex-1));
}