lib/xregexp/xregexp.js
function runTokens(pattern, flags, pos, scope, context) {
    var i = tokens.length,
        leadChar = pattern.charAt(pos),
        result = null,
        match,
        t;

    // Run in reverse insertion order
    while (i--) {
        t = tokens[i];
        if (
            (t.leadChar && t.leadChar !== leadChar) ||
            (t.scope !== scope && t.scope !== 'all') ||
            (t.flag && flags.indexOf(t.flag) === -1)
        ) {
            continue;
        }

        match = XRegExp.exec(pattern, t.regex, pos, 'sticky');
        if (match) {
            result = {
                matchLength: match[0].length,
                output: t.handler.call(context, match, scope, flags),
                reparse: t.reparse
            };
            // Finished with token tests
            break;
        }
    }

    return result;
}
function runTokens(pattern, flags, pos, scope, context) {
    var i = tokens.length,
        leadChar = pattern.charAt(pos),
        result = null,
        match,
        t;

    // Run in reverse insertion order
    while (i--) {
        t = tokens[i];
        if (
            (t.leadChar && t.leadChar !== leadChar) ||
            (t.scope !== scope && t.scope !== 'all') ||
            (t.flag && flags.indexOf(t.flag) === -1)
        ) {
            continue;
        }

        match = XRegExp.exec(pattern, t.regex, pos, 'sticky');
        if (match) {
            result = {
                matchLength: match[0].length,
                output: t.handler.call(context, match, scope, flags),
                reparse: t.reparse
            };
            // Finished with token tests
            break;
        }
    }

    return result;
}
function runTokens ( pattern , flags , pos , scope , context ) { var i = tokens . length , leadChar = pattern . charAt ( pos ) , result = null , match , t ; // Run in reverse insertion order while ( i -- ) { t = tokens [ i ] ; if ( ( t . leadChar && t . leadChar !== leadChar ) || ( t . scope !== scope && t . scope !== 'all' ) || ( t . flag && flags . indexOf ( t . flag ) === - 1 ) ) { continue ; } match = XRegExp . exec ( pattern , t . regex , pos , 'sticky' ) ; if ( match ) { result = { matchLength : match [ 0 ] . length , output : t . handler . call ( context , match , scope , flags ) , reparse : t . reparse } ; // Finished with token tests break ; } } return result ; }
Runs built-in and custom regex syntax tokens in reverse insertion order at the specified
position, until a match is found.

@private
@param {String} pattern Original pattern from which an XRegExp object is being built.
@param {String} flags Flags being used to construct the regex.
@param {Number} pos Position to search for tokens within `pattern`.
@param {Number} scope Regex scope to apply: 'default' or 'class'.
@param {Object} context Context object to use for token handler functions.
@returns {Object} Object with properties `matchLength`, `output`, and `reparse`; or `null`.
Runs built - in and custom regex syntax tokens in reverse insertion order at the specified position until a match is found .