lib/index.js
function parse (expr) {
		var finalRegexp,
			strSlashPref;

		if (typeof expr !== 'string') {
			// Handle RegExp `expr`
			if (expr instanceof RegExp) {
				finalRegexp = new RegExp(expr);
				finalRegexp.query = execQuery;

				return finalRegexp;
			}

			throw new TypeError(
				'Usage: qbus.parse(<`query` = String|RegExp>)\n' + 
				'Got:   qbus.parse(<`' + typeof expr + '` = ' + expr + '>)'
			);
		}
		
		strSlashPref = expr[expr.length - 1] === '/';

		// Trim slashes and remove doubles
		expr = normalizePath(expr);

		// Pass everything from and including possible beginning frontslash
		// until and not including the next frontslash, to `parseLevel`.
		expr = expr.replace(/\/?[^\/]+?(?=\/|$)/g, function (match, index) {
			// Return level if it doesn't contain any modifiers.
			// : must be preceeded by / or start of string to count
			// ? must be used with valid : to count (so we don't need to check for that)
			// * always counts
			if (match.indexOf('*') === -1 && (match.length <= 2 || !/(^|\/)+\:+?/.test(match))) {
				return match.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
			}

			var slashSuff = match[0] === '/' ? '/' : '',
				slashPref = !!expr[match.length + index] || strSlashPref,
				level = slashSuff ? match.substr(1) : match,
				firstChar = level[0],
				lastChar = level.substr(-1);
			
			// Handle captures
			if (firstChar === ':') {
				// Handle optional :capture?
				if (lastChar === '?') {
					// Wrap any preceding slash in the optional capture group
					return (slashSuff ? '(?:/([^/]+?))?' : '([^/]+?)?');
				}

				// Handle mandatory :capture
				return slashSuff + '([^/]+?)';
			}

			// All matches that end with a slash or does not end with * are easy.
			// We'll just choose to capture anything except a frontslash.
			// 
			// /some/stuff*/   =>   /some/stuff([^/]+)?/
			// /some/st*ff/    =>   /some/st([^/]+)?ff/
			if (slashPref || lastChar !== '*') {
				return slashSuff + level.replace(/\*/g, '([^/]+)?');
			}

			// Handle all matches that ends with * and are not followd by frontslash; 'stuff*', '*'.
			// We'll replace all asterisks except the last with catch-alls. The last one is omitted and replaced with
			// a pattern that matches everything up until, but not included, the last frontslash in the string or end-of-string.
			// 
			// /some/stuff* => some/stuff(.*?(?:(?=\/$)|(?=$)))?
			// /some/st*ff* => some/st(.*)?ff(.*?(?:(?=\/$)|(?=$)))?
			// /*           => (.*?(?:(?=\\/$)|(?=$)))?
			return slashSuff + level.replace(/\*(?!$)/g, '(.*)?').slice(0, -1) + '(.*?(?:(?=/$)|(?=$)))?';
		});

		// Create RegExp object from the parsed query
		finalRegexp = new RegExp('^/?' + expr  + '/?$', 'i');

		// Add `execQuery` to it's properties
		finalRegexp.query = execQuery;

		return finalRegexp;
	}
function parse (expr) {
		var finalRegexp,
			strSlashPref;

		if (typeof expr !== 'string') {
			// Handle RegExp `expr`
			if (expr instanceof RegExp) {
				finalRegexp = new RegExp(expr);
				finalRegexp.query = execQuery;

				return finalRegexp;
			}

			throw new TypeError(
				'Usage: qbus.parse(<`query` = String|RegExp>)\n' + 
				'Got:   qbus.parse(<`' + typeof expr + '` = ' + expr + '>)'
			);
		}
		
		strSlashPref = expr[expr.length - 1] === '/';

		// Trim slashes and remove doubles
		expr = normalizePath(expr);

		// Pass everything from and including possible beginning frontslash
		// until and not including the next frontslash, to `parseLevel`.
		expr = expr.replace(/\/?[^\/]+?(?=\/|$)/g, function (match, index) {
			// Return level if it doesn't contain any modifiers.
			// : must be preceeded by / or start of string to count
			// ? must be used with valid : to count (so we don't need to check for that)
			// * always counts
			if (match.indexOf('*') === -1 && (match.length <= 2 || !/(^|\/)+\:+?/.test(match))) {
				return match.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
			}

			var slashSuff = match[0] === '/' ? '/' : '',
				slashPref = !!expr[match.length + index] || strSlashPref,
				level = slashSuff ? match.substr(1) : match,
				firstChar = level[0],
				lastChar = level.substr(-1);
			
			// Handle captures
			if (firstChar === ':') {
				// Handle optional :capture?
				if (lastChar === '?') {
					// Wrap any preceding slash in the optional capture group
					return (slashSuff ? '(?:/([^/]+?))?' : '([^/]+?)?');
				}

				// Handle mandatory :capture
				return slashSuff + '([^/]+?)';
			}

			// All matches that end with a slash or does not end with * are easy.
			// We'll just choose to capture anything except a frontslash.
			// 
			// /some/stuff*/   =>   /some/stuff([^/]+)?/
			// /some/st*ff/    =>   /some/st([^/]+)?ff/
			if (slashPref || lastChar !== '*') {
				return slashSuff + level.replace(/\*/g, '([^/]+)?');
			}

			// Handle all matches that ends with * and are not followd by frontslash; 'stuff*', '*'.
			// We'll replace all asterisks except the last with catch-alls. The last one is omitted and replaced with
			// a pattern that matches everything up until, but not included, the last frontslash in the string or end-of-string.
			// 
			// /some/stuff* => some/stuff(.*?(?:(?=\/$)|(?=$)))?
			// /some/st*ff* => some/st(.*)?ff(.*?(?:(?=\/$)|(?=$)))?
			// /*           => (.*?(?:(?=\\/$)|(?=$)))?
			return slashSuff + level.replace(/\*(?!$)/g, '(.*)?').slice(0, -1) + '(.*?(?:(?=/$)|(?=$)))?';
		});

		// Create RegExp object from the parsed query
		finalRegexp = new RegExp('^/?' + expr  + '/?$', 'i');

		// Add `execQuery` to it's properties
		finalRegexp.query = execQuery;

		return finalRegexp;
	}
function parse ( expr ) { var finalRegexp , strSlashPref ; if ( typeof expr !== 'string' ) { // Handle RegExp `expr` if ( expr instanceof RegExp ) { finalRegexp = new RegExp ( expr ) ; finalRegexp . query = execQuery ; return finalRegexp ; } throw new TypeError ( 'Usage: qbus.parse(<`query` = String|RegExp>)\n' + 'Got:   qbus.parse(<`' + typeof expr + '` = ' + expr + '>)' ) ; } strSlashPref = expr [ expr . length - 1 ] === '/' ; // Trim slashes and remove doubles expr = normalizePath ( expr ) ; // Pass everything from and including possible beginning frontslash // until and not including the next frontslash, to `parseLevel`. expr = expr . replace ( / \/?[^\/]+?(?=\/|$) / g , function ( match , index ) { // Return level if it doesn't contain any modifiers. // : must be preceeded by / or start of string to count // ? must be used with valid : to count (so we don't need to check for that) // * always counts if ( match . indexOf ( '*' ) === - 1 && ( match . length <= 2 || ! / (^|\/)+\:+? / . test ( match ) ) ) { return match . replace ( / [-\/\\^$*+?.()|[\]{}] / g , '\\$&' ) ; } var slashSuff = match [ 0 ] === '/' ? '/' : '' , slashPref = ! ! expr [ match . length + index ] || strSlashPref , level = slashSuff ? match . substr ( 1 ) : match , firstChar = level [ 0 ] , lastChar = level . substr ( - 1 ) ; // Handle captures if ( firstChar === ':' ) { // Handle optional :capture? if ( lastChar === '?' ) { // Wrap any preceding slash in the optional capture group return ( slashSuff ? '(?:/([^/]+?))?' : '([^/]+?)?' ) ; } // Handle mandatory :capture return slashSuff + '([^/]+?)' ; } // All matches that end with a slash or does not end with * are easy. // We'll just choose to capture anything except a frontslash. //  // /some/stuff*/   =>   /some/stuff([^/]+)?/ // /some/st*ff/    =>   /some/st([^/]+)?ff/ if ( slashPref || lastChar !== '*' ) { return slashSuff + level . replace ( / \* / g , '([^/]+)?' ) ; } // Handle all matches that ends with * and are not followd by frontslash; 'stuff*', '*'. // We'll replace all asterisks except the last with catch-alls. The last one is omitted and replaced with // a pattern that matches everything up until, but not included, the last frontslash in the string or end-of-string. //  // /some/stuff* => some/stuff(.*?(?:(?=\/$)|(?=$)))? // /some/st*ff* => some/st(.*)?ff(.*?(?:(?=\/$)|(?=$)))? // /*           => (.*?(?:(?=\\/$)|(?=$)))? return slashSuff + level . replace ( / \*(?!$) / g , '(.*)?' ) . slice ( 0 , - 1 ) + '(.*?(?:(?=/$)|(?=$)))?' ; } ) ; // Create RegExp object from the parsed query finalRegexp = new RegExp ( '^/?' + expr + '/?$' , 'i' ) ; // Add `execQuery` to it's properties finalRegexp . query = execQuery ; return finalRegexp ; }
Converts given expression to RegExp.
If a RegExp is given it will copy it and add 'execQuery' to its properties.

@method     emit
@param      {String|RegExp}  expr   The string to convert or RegExp to add 'execQuery'.
@return     {RegExp}
Converts given expression to RegExp . If a RegExp is given it will copy it and add execQuery to its properties .