Created
July 14, 2013 14:50
-
-
Save krmgns/5994519 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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