Last active
June 30, 2016 06:49
-
-
Save leodutra/ae22429e816cafaaa6bdaa79778cf61e to your computer and use it in GitHub Desktop.
Simple multiple Regular Expresion (Regex) matches.
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
function regexMultiMatch(str, regex, fn) { | |
// clone for no regex.lastIndex problems | |
var cloneRegExp = new RegExp(regex.source, regex.flags || | |
(regex.global ? 'g' : '') + (regex.ignoreCase ? 'i' : '') + (regex.multiline ? 'm' : '')) | |
fn.apply(null, regex.exec(str)) | |
if (regex.global) { | |
var match | |
while((match = regex.exec(str))) fn.apply(null, match) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment