Skip to content

Instantly share code, notes, and snippets.

@krmgns
Created July 14, 2013 14:50
Show Gist options
  • Save krmgns/5994519 to your computer and use it in GitHub Desktop.
Save krmgns/5994519 to your computer and use it in GitHub Desktop.
if (typeof RegExp.prototype.matchAll !== "function") {
RegExp.prototype.matchAll = function(v) {
var tmp = ""+ this, // So this.toString
src = tmp.lastIndexOf("/"),
pattern = tmp.substring(1, src),
flags = tmp.substring(src + 1, tmp.length);
// Never forget "g", that prepends infinite loops for "while"
if (flags.indexOf("g") == -1) {
flags += "g";
}
var re = new RegExp(pattern, flags);
var ms = [], m;
while (m = re.exec(v)) {
ms.push(m);
}
return ms;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment