Sha256: dc723c403a012622f3fee283157cb98e3a642c6a7654f45faf9e94a0deec9b8e
Contents?: true
Size: 911 Bytes
Versions: 29
Compression:
Stored size: 911 Bytes
Contents
/* --- name : sg-regex-tools description : A few super-handy tools for messing around with RegExp authors : Thomas Aylott copyright : © 2010 Thomas Aylott license : MIT provides : [combineRegExp] ... */ ;(function(exports){ exports.combineRegExp = function(regex, group){ if (regex.source) regex = [regex] var names = [], i, source = '', this_source for (i = 0; i < regex.length; ++i){ if (!regex[i]) continue this_source = regex[i].source || ''+regex[i] if (this_source == '|') source += '|' else { source += (group?'(':'') + this_source.replace(/\s/g,'') + (group?')':'') if (group) names.push(group) } if (regex[i].names) names = names.concat(regex[i].names) } regex = new RegExp(source,'gm') // [key] → 1 for (i = -1; i < names.length; ++i) names[names[i]] = i + 1 // [1] → key regex.names = names return regex } }(typeof exports != 'undefined' ? exports : this))
Version data entries
29 entries across 29 versions & 1 rubygems