Skip to content

Instantly share code, notes, and snippets.

@allex
Forked from simonw/regex-findall.js
Created July 13, 2012 16:12
Show Gist options
  • Save allex/3105737 to your computer and use it in GitHub Desktop.
Save allex/3105737 to your computer and use it in GitHub Desktop.
/* 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