Skip to content

Instantly share code, notes, and snippets.

@leodutra
Last active June 30, 2016 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leodutra/ae22429e816cafaaa6bdaa79778cf61e to your computer and use it in GitHub Desktop.
Save leodutra/ae22429e816cafaaa6bdaa79778cf61e to your computer and use it in GitHub Desktop.
Simple multiple Regular Expresion (Regex) matches.
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