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

Version Path
jsus-0.4.0 spec/data/JsonPackage/Source/sg-regex-tools.js
jsus-0.3.6 spec/data/JsonPackage/Source/sg-regex-tools.js
jsus-0.3.5 spec/data/JsonPackage/Source/sg-regex-tools.js
jsus-0.3.4 spec/data/JsonPackage/Source/sg-regex-tools.js
jsus-0.3.3 spec/data/JsonPackage/Source/sg-regex-tools.js
jsus-0.3.2 spec/data/JsonPackage/Source/sg-regex-tools.js
jsus-0.3.1 spec/data/JsonPackage/Source/sg-regex-tools.js
jsus-0.3.0 spec/data/JsonPackage/Source/sg-regex-tools.js
jsus-0.2.7 spec/data/JsonPackage/Source/sg-regex-tools.js
jsus-0.2.6 spec/data/JsonPackage/Source/sg-regex-tools.js
jsus-0.2.5 spec/data/JsonPackage/Source/sg-regex-tools.js
jsus-0.2.4 spec/data/JsonPackage/Source/sg-regex-tools.js
jsus-0.2.3 spec/data/JsonPackage/Source/sg-regex-tools.js
jsus-0.2.2 spec/data/JsonPackage/Source/sg-regex-tools.js
jsus-0.2.1 spec/data/JsonPackage/Source/sg-regex-tools.js
jsus-0.2.0 spec/data/JsonPackage/Source/sg-regex-tools.js
jsus-0.1.22 spec/data/JsonPackage/Source/sg-regex-tools.js
jsus-0.1.21 spec/data/JsonPackage/Source/sg-regex-tools.js
jsus-0.1.20 spec/data/JsonPackage/Source/sg-regex-tools.js
jsus-0.1.19 spec/data/JsonPackage/Source/sg-regex-tools.js