function _findAllMatchingSelectorsInText(text, selector, mode) {
        var allSelectors = extractAllSelectors(text, mode);
        var result = [];

        // For now, we only match the rightmost simple selector, and ignore
        // attribute selectors and pseudo selectors
        var classOrIdSelector = selector[0] === "." || selector[0] === "#";

        // Escape initial "." in selector, if present.
        if (selector[0] === ".") {
            selector = "\\" + selector;
        }

        if (!classOrIdSelector) {
            // Tag selectors must have nothing, whitespace, or a combinator before it.
            selector = "(^|[\\s>+~])" + selector;
        }

        var re = new RegExp(selector + "(\\[[^\\]]*\\]|:{1,2}[\\w-()]+|\\.[\\w-]+|#[\\w-]+)*\\s*$", classOrIdSelector ? "" : "i");
        allSelectors.forEach(function (entry) {
            var actualSelector = entry.selector;
            if (entry.selector.indexOf("&") !== -1 && entry.parentSelectors) {
                var selectorArray = entry.parentSelectors.split(" / ");
                selectorArray.push(entry.selector);
                actualSelector = _getSelectorInFinalCSSForm(selectorArray);
            }
            if (actualSelector.search(re) !== -1) {
                result.push(entry);
            } else if (!classOrIdSelector) {
                // Special case for tag selectors - match "*" as the rightmost character
                if (/\*\s*$/.test(actualSelector)) {
                    result.push(entry);
                }
            }
        });

        return result;
    }
Finds all instances of the specified selector in "text".
Returns an Array of Objects with start and end properties.

For now, we only support simple selectors. This function will need to change
dramatically to support full selectors.

FUTURE: (JRB) It would be nice to eventually use the browser/jquery to do the selector evaluation.
One way to do this would be to take the user's HTML, add a special attribute to every tag with a UID,
and then construct a DOM (using the commented out code above). Then, give this DOM and the selector to
jquery and ask what matches. If the node that the user's cursor is in comes back from jquery, then
we know the selector applies.

@param {!string} text CSS text to search
@param {!string} selector selector to search for
@param {!string} mode language mode of the document that text belongs to
@return {Array.<{selectorGroupStartLine:number, declListEndLine:number, selector:string}>}
     Array of objects containing the start and end line numbers (0-based, inclusive range) for each
     matched selector.