Created
July 4, 2016 10:32
-
-
Save RodolpheGohard/d9c304def8e436998d4a09baf8f20d19 to your computer and use it in GitHub Desktop.
get all matches of a regex on a string.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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