Skip to content

Instantly share code, notes, and snippets.

@RodolpheGohard
Created July 4, 2016 10:32
Show Gist options
  • Save RodolpheGohard/d9c304def8e436998d4a09baf8f20d19 to your computer and use it in GitHub Desktop.
Save RodolpheGohard/d9c304def8e436998d4a09baf8f20d19 to your computer and use it in GitHub Desktop.
get all matches of a regex on a string.
// see https://github.com/lodash/lodash/issues/2459
const getAllMatches = (source, regex) => {
const matches = [];
source.replace(regex, function() {
matches.push({
match: arguments[0],
offset: arguments[arguments.length-2],
groups: Array.prototype.slice.call(arguments, 1, -2)
});
return arguments[0];
});
return matches;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment