src/JSUtils/Preferences.js
function settingsToRegExp(settings, baseRegExp, defaultRegExp) {
        var regExpString = "";

        if (settings instanceof Array && settings.length > 0) {

            // Append base settings to user settings. The base
            // settings are builtin and cannot be overridden.
            if (baseRegExp) {
                settings.push("/" + baseRegExp.source + "/");
            }

            // convert each string, with optional wildcards to an equivalent
            // string in a regular expression.
            settings.forEach(function (value, index) {

                if (typeof value === "string") {
                    var isRegExp = value[0] === '/' && value[value.length - 1] === '/';

                    if (isRegExp) {
                        value = value.substring(1, value.length - 1);
                    } else {
                        value = StringUtils.regexEscape(value);

                        // convert user input wildcard, "*" or "?", to a regular
                        // expression. We can just replace the escaped "*" or "?"
                        // since we know it is a wildcard.
                        value = value.replace("\\?", ".?");
                        value = value.replace("\\*", ".*");

                        // Add "^" and "$" to prevent matching in the middle of strings.
                        value = "^" + value + "$";
                    }

                    if (index > 0) {
                        regExpString += "|";
                    }

                    regExpString = regExpString.concat(value);
                }
            });
        }

        if (!regExpString) {
            var defaultParts = [];
            if (baseRegExp) {
                defaultParts.push(baseRegExp.source);
            }
            if (defaultRegExp) {
                defaultParts.push(defaultRegExp.source);
            }
            if (defaultParts.length > 0) {
                regExpString  = defaultParts.join("|");
            } else {
                return null;
            }
        }

        return new RegExp(regExpString);
    }
function settingsToRegExp(settings, baseRegExp, defaultRegExp) {
        var regExpString = "";

        if (settings instanceof Array && settings.length > 0) {

            // Append base settings to user settings. The base
            // settings are builtin and cannot be overridden.
            if (baseRegExp) {
                settings.push("/" + baseRegExp.source + "/");
            }

            // convert each string, with optional wildcards to an equivalent
            // string in a regular expression.
            settings.forEach(function (value, index) {

                if (typeof value === "string") {
                    var isRegExp = value[0] === '/' && value[value.length - 1] === '/';

                    if (isRegExp) {
                        value = value.substring(1, value.length - 1);
                    } else {
                        value = StringUtils.regexEscape(value);

                        // convert user input wildcard, "*" or "?", to a regular
                        // expression. We can just replace the escaped "*" or "?"
                        // since we know it is a wildcard.
                        value = value.replace("\\?", ".?");
                        value = value.replace("\\*", ".*");

                        // Add "^" and "$" to prevent matching in the middle of strings.
                        value = "^" + value + "$";
                    }

                    if (index > 0) {
                        regExpString += "|";
                    }

                    regExpString = regExpString.concat(value);
                }
            });
        }

        if (!regExpString) {
            var defaultParts = [];
            if (baseRegExp) {
                defaultParts.push(baseRegExp.source);
            }
            if (defaultRegExp) {
                defaultParts.push(defaultRegExp.source);
            }
            if (defaultParts.length > 0) {
                regExpString  = defaultParts.join("|");
            } else {
                return null;
            }
        }

        return new RegExp(regExpString);
    }
function settingsToRegExp ( settings , baseRegExp , defaultRegExp ) { var regExpString = "" ; if ( settings instanceof Array && settings . length > 0 ) { // Append base settings to user settings. The base // settings are builtin and cannot be overridden. if ( baseRegExp ) { settings . push ( "/" + baseRegExp . source + "/" ) ; } // convert each string, with optional wildcards to an equivalent // string in a regular expression. settings . forEach ( function ( value , index ) { if ( typeof value === "string" ) { var isRegExp = value [ 0 ] === '/' && value [ value . length - 1 ] === '/' ; if ( isRegExp ) { value = value . substring ( 1 , value . length - 1 ) ; } else { value = StringUtils . regexEscape ( value ) ; // convert user input wildcard, "*" or "?", to a regular // expression. We can just replace the escaped "*" or "?" // since we know it is a wildcard. value = value . replace ( "\\?" , ".?" ) ; value = value . replace ( "\\*" , ".*" ) ; // Add "^" and "$" to prevent matching in the middle of strings. value = "^" + value + "$" ; } if ( index > 0 ) { regExpString += "|" ; } regExpString = regExpString . concat ( value ) ; } } ) ; } if ( ! regExpString ) { var defaultParts = [ ] ; if ( baseRegExp ) { defaultParts . push ( baseRegExp . source ) ; } if ( defaultRegExp ) { defaultParts . push ( defaultRegExp . source ) ; } if ( defaultParts . length > 0 ) { regExpString = defaultParts . join ( "|" ) ; } else { return null ; } } return new RegExp ( regExpString ) ; }
Convert an array of strings with optional wildcards, to an equivalent
regular expression.

@param {Array.<string|RegExp>} settings from the file (note: this may be mutated by this function)
@param {?RegExp} baseRegExp - base regular expression that is always used
@param {?RegExp} defaultRegExp - additional regular expression that is only used if the user has not configured settings
@return {RegExp} Regular expression that captures the array of string
with optional wildcards.
Convert an array of strings with optional wildcards to an equivalent regular expression .