Skip to content

Instantly share code, notes, and snippets.

@ianldgs
Last active October 2, 2019 11:01
Show Gist options
  • Save ianldgs/63828ec6dfa3cf0667871de2128d4351 to your computer and use it in GitHub Desktop.
Save ianldgs/63828ec6dfa3cf0667871de2128d4351 to your computer and use it in GitHub Desktop.
/**
* @link https://jsperf.com/javascript-string-character-finder/7
*/
function indexesOf(string, regex) {
var match,
indexes = {};
regex = new RegExp(regex);
while (match = regex.exec(string)) {
if (!indexes[match[0]]) indexes[match[0]] = [];
indexes[match[0]].push(match.index);
}
return indexes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment