Skip to content

Instantly share code, notes, and snippets.

@k-gun

k-gun/matchAll.js

Created Jul 14, 2013
Embed
What would you like to do?
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
You can’t perform that action at this time.