For example i want to get the first character of a string using the '^' meta char. This will make the following code crash because exec() never returns null. Is there a way to make it works without changing the regex ? (At least not crash ?)
const regexp = /^/g;
const str = 'Lorem ipsum';
let regexMatches = [];
while ((matches = regexp.exec(str)) !== null) {
regexMatches.push({str: matches[0], index: regexp.lastIndex});
}