-
-
Save allex/3105737 to your computer and use it in GitHub Desktop.
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
/* Inspired by Python's useful re.findall method */ | |
function findall(regex, str) { | |
var matches = [], m; | |
regex.lastIndex = 0; | |
while (m = regex.exec(str, regex.lastIndex)) { | |
matches[matches.length] = m; | |
} | |
return matches; | |
} | |
/* Example usage: | |
var matches = findall(/\d+/, '123 456 789'); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment