Sha256: 47acd8550c9ba4d28bf7abdf2a757c5f67b49511b43e93af56dd4a6f746bf939

Contents?: true

Size: 999 Bytes

Versions: 7

Compression:

Stored size: 999 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)
	}
	try {
		regex = new RegExp(source,'gm')
	}
	catch (e){
		throw new SyntaxError('Invalid Syntax: ' + source +'; '+ e)
	}
	// [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

7 entries across 7 versions & 1 rubygems

Version Path
lsd_rails-0.1.6 Packages/Sheet.js/Source/sg-regex-tools.js
lsd_rails-0.1.5 Packages/Sheet.js/Source/sg-regex-tools.js
lsd_rails-0.1.4 Packages/Sheet.js/Source/sg-regex-tools.js
lsd_rails-0.1.3 Packages/Sheet.js/Source/sg-regex-tools.js
lsd_rails-0.1.2 Packages/Sheet.js/Source/sg-regex-tools.js
lsd_rails-0.1.1 Packages/Sheet.js/Source/sg-regex-tools.js
lsd_rails-0.1 Packages/Sheet.js/Source/sg-regex-tools.js