asciidoctor Documentation - tag::compareMatches[]
777061
private Category getSelectedCategoryByMatch() {
    // Strategy: Go from most specific match to most unspecific match
    Category firstFilteredSetting =
        filteredSettingsLst.size() == 0 ? null : settingCategoryMap.get(filteredSettingsLst.get(0));
    Category firstFilteredGroup =
        filteredGroupsLst.size() == 0 ? null : groupCategoryMap.get(filteredGroupsLst.get(0));
    Category firstFilteredCategory =
        filteredCategoriesLst.size() == 0 ? null : filteredCategoriesLst.get(0);
    return compareMatches(
        firstFilteredSetting, firstFilteredGroup, firstFilteredCategory,
        settingMatches, groupMatches, categoryMatches
    );
  }
644316
private static boolean matches(String matchHeader, String toMatch) {
        String[] matchValues = matchHeader.split("\\s*,\\s*");
        Arrays.sort(matchValues);
        return Arrays.binarySearch(matchValues, toMatch) > -1
                || Arrays.binarySearch(matchValues, "*") > -1;
    }
428611
protected function _processCodeBlock($matches)
    {
        list($block, $openTag, $tagName, $lang, $code, $closeTag) = $matches;
        unset($matches);

        // check language
        $lang = $this->validLang($lang);
        $code = html_entity_decode($code, ENT_QUOTES); // decode text in code block as GeSHi will re-encode it.

        if (isset($this->containerMap[$tagName])) {
            $patt = '/' . preg_quote($tagName) . '/';
            $openTag = preg_replace($patt, $this->containerMap[$tagName][0], $openTag);
            $closeTag = preg_replace($patt, $this->containerMap[$tagName][1], $closeTag);
        }

        if ($this->showPlainTextButton) {
            $button = '<a href="#null" class="geshi-plain-text">Show Plain Text</a>';
            $openTag = $button . $openTag;
        }

        if ($lang) {
            $highlighted = $this->highlightText(trim($code), $lang);
            return $openTag . $highlighted . $closeTag;
        }
        return $openTag . $code . $closeTag;
    }
873608
public function comparisonOperator()
    {
        switch ($this->lexer->lookahead['value']) {
            case '=':
                $this->match(Lexer::T_EQUALS);

                return '=';
            case '<':
                $this->match(Lexer::T_LOWER_THAN);
                $operator = '<';

                if ($this->lexer->isNextToken(Lexer::T_EQUALS)) {
                    $this->match(Lexer::T_EQUALS);
                    $operator .= '=';
                } else if ($this->lexer->isNextToken(Lexer::T_GREATER_THAN)) {
                    $this->match(Lexer::T_GREATER_THAN);
                    $operator .= '>';
                }

                return $operator;

            case '>':
                $this->match(Lexer::T_GREATER_THAN);
                $operator = '>';

                if ($this->lexer->isNextToken(Lexer::T_EQUALS)) {
                    $this->match(Lexer::T_EQUALS);
                    $operator .= '=';
                }

                return $operator;

            case '!':
                $this->match(Lexer::T_NEGATE);
                $this->match(Lexer::T_EQUALS);

                return '<>';

            default:
                $this->syntaxError('=, <, <=, <>, >, >=, !=');
        }

        return null;
    }
267111
boolean matchComment(
            final boolean blockMatching,
            final int markupLevel, final int markupBlockIndex) {

        checkMarkupLevel(markupLevel);

        if (this.markupSelectorItem.anyLevel() || markupLevel == 0 || (this.prev != null && this.prev.matchedMarkupLevels[markupLevel - 1])) {
            // This text has not matched yet, but might match, so we should check

            this.matchesThisLevel = this.markupSelectorItem.matchesComment(markupBlockIndex, this.markupBlockMatchingCounter);

            if (matchesPreviousOrCurrentLevel(markupLevel)) {
                // This filter was already matched by a previous level (through an "open" event), so just delegate to next.

                if (this.next != null) {
                    return this.next.matchComment(blockMatching, markupLevel, markupBlockIndex);
                }
                return (blockMatching? true : this.matchesThisLevel);

            } else if (this.matchesThisLevel) {
                // This filter was not matched before. So the fact that it matches now means we need to consume it,
                // therefore not delegating.

                return (this.next == null);

            }

        } else if (matchesPreviousOrCurrentLevel(markupLevel)) {
            // This filter was already matched by a previous level (through an "open" event), so just delegate to next.

            if (this.next != null) {
                return this.next.matchComment(blockMatching, markupLevel, markupBlockIndex);
            }
            return blockMatching;

        }

        return false;

    }
685392
function it_matches_identifiers()
    {
        $this->match('123')->shouldReturn('123');
        $this->match('3.14')->shouldReturn('3.14');
        $this->match('-123')->shouldReturn('-123');
    }
1275310
def matches(language)
      values.select {|v|
        v = v.match(/^(.+?)-/) ? $1 : v if @first_level_match
        v == language || v == '*' || (language.match(/^(.+?)-/) && v == $1)
      }.sort {|a, b|
        # "*" gets least precedence, any others are compared based on length.
        a == '*' ? -1 : (b == '*' ? 1 : a.length <=> b.length)
      }.reverse
    end
779696
function elementMatches (el, selector) {
  if (el.matches) { return el.matches(selector) }
  if (el.msMatchesSelector) { return el.msMatchesSelector(selector) }
  if (el.webkitMatchesSelector) { return el.webkitMatchesSelector(selector) }
}
1270932
def matches(self, s):
    """"""
    regex_matches = self.compiled_regex.search(s) is not None
    return not regex_matches if self.inverted else regex_matches
350074
def match_selectors(self, el, selectors):
        """"""

        match = False
        is_not = selectors.is_not
        is_html = selectors.is_html

        # Internal selector lists that use the HTML flag, will automatically get the `html` namespace.
        if is_html:
            namespaces = self.namespaces
            iframe_restrict = self.iframe_restrict
            self.namespaces = {'html': NS_XHTML}
            self.iframe_restrict = True

        if not is_html or self.is_html:
            for selector in selectors:
                match = is_not
                # We have a un-matchable situation (like `:focus` as you can focus an element in this environment)
                if isinstance(selector, ct.SelectorNull):
                    continue
                # Verify tag matches
                if not self.match_tag(el, selector.tag):
                    continue
                # Verify tag is defined
                if selector.flags & ct.SEL_DEFINED and not self.match_defined(el):
                    continue
                # Verify element is root
                if selector.flags & ct.SEL_ROOT and not self.match_root(el):
                    continue
                # Verify element is scope
                if selector.flags & ct.SEL_SCOPE and not self.match_scope(el):
                    continue
                # Verify `nth` matches
                if not self.match_nth(el, selector.nth):
                    continue
                if selector.flags & ct.SEL_EMPTY and not self.match_empty(el):
                    continue
                # Verify id matches
                if selector.ids and not self.match_id(el, selector.ids):
                    continue
                # Verify classes match
                if selector.classes and not self.match_classes(el, selector.classes):
                    continue
                # Verify attribute(s) match
                if not self.match_attributes(el, selector.attributes):
                    continue
                # Verify ranges
                if selector.flags & RANGES and not self.match_range(el, selector.flags & RANGES):
                    continue
                # Verify language patterns
                if selector.lang and not self.match_lang(el, selector.lang):
                    continue
                # Verify pseudo selector patterns
                if selector.selectors and not self.match_subselectors(el, selector.selectors):
                    continue
                # Verify relationship selectors
                if selector.relation and not self.match_relations(el, selector.relation):
                    continue
                # Validate that the current default selector match corresponds to the first submit button in the form
                if selector.flags & ct.SEL_DEFAULT and not self.match_default(el):
                    continue
                # Validate that the unset radio button is among radio buttons with the same name in a form that are
                # also not set.
                if selector.flags & ct.SEL_INDETERMINATE and not self.match_indeterminate(el):
                    continue
                # Validate element directionality
                if selector.flags & DIR_FLAGS and not self.match_dir(el, selector.flags & DIR_FLAGS):
                    continue
                # Validate that the tag contains the specified text.
                if not self.match_contains(el, selector.contains):
                    continue
                match = not is_not
                break

        # Restore actual namespaces being used for external selector lists
        if is_html:
            self.namespaces = namespaces
            self.iframe_restrict = iframe_restrict

        return match
245247
def matches(charset)
      values.select {|v|
        v == charset || v == '*'
      }.sort {|a, b|
        # "*" gets least precedence, any others should be equal.
        a == '*' ? 1 : (b == '*' ? -1 : 0)
      }
    end
67703
def __cmp(self, other, comparitor):
        """"""
        if not isinstance(other, TagWidget):
            return NotImplemented

        self_len = len(self.translated)
        oth_len = len(other.translated)

        if (self_len == 1) is not (oth_len == 1):
            return comparitor(self_len, oth_len)
        return comparitor(self.translated.lower(), other.translated.lower())
491522
def find_q_matches(q_values, available, &matcher)
      matcher ||= lambda { |a, b| a == b }

      matches = []

      case q_values
      when Array
      when String
        q_values = parse_q_values(q_values)
      when NilClass
        q_values = []
      else
        raise TypeError, "unknown q_values type: #{q_values.class}"
      end

      q_values.each do |accepted, quality|
        if match = available.find { |option| matcher.call(option, accepted) }
          matches << [match, quality]
        end
      end

      matches.sort_by! { |match, quality| -quality }
      matches.map! { |match, quality| match }
      matches
    end
316683
function matches(str, match) {
    if (Array.isArray(match)) return match.indexOf(str) > -1;
    return match.test(str);
}
513499
function isMatch(file, license, rate, srcNLReg) {
        var srcLines = file.contents.toString('utf8').split(/\r?\n/),
                templateLines = license.split(/\r?\n/),
                type = path.extname(file.path),
                matchRates = 0,
                removed = false;

        // after '<?php' has new line, remove it 
        switch (type) {
            case '.php':
                if (srcLines[1].replace(/\s/, '') === '') {
                    srcLines.splice(1, 1);
                    removed = true;
                }
                break;
            default:
                break;
        }

        // count match line
        var minLength = templateLines.length > srcLines.length ? srcLines.length : templateLines.length;
        for (var i = 0; i < minLength; i++) {
            if (templateLines[templateLines.length - 1] === '' && i === templateLines.length - 1) {
                matchRates += 1;
            } else {
                switch (type) {
                    case '.php':
                        matchRates += getMatchRate(srcLines[i + 1], templateLines[i]);
                        break;
                    default:
                        matchRates += getMatchRate(srcLines[i], templateLines[i]);
                        break;
                }
            }
        }

        // has similar license, remove the license.
        var matchPer = matchRates / templateLines.length;

        if (matchPer >= rate && matchPer < 1) {
            // remove
            switch (type) {
                case '.php':
                    if (srcLines[templateLines.length].replace(/\s/, '') === '' && !removed) {
                        // after license, should be have a blank line. if has not, we don't need remove blank line. && after '<?php' has not new line
                        srcLines.splice(1, templateLines.length);
                    } else {
                        srcLines.splice(1, templateLines.length - 1);
                    }
                    file.contents = new Buffer(srcLines.join(srcNLReg));
                    break;
                default:
                    // after license, should be have a blank line. if have not, we don't need remove blank line.
                    if (srcLines[templateLines.length - 1].replace(/\s/, '') === '') {
                        srcLines.splice(0, templateLines.length);
                    } else {
                        srcLines.splice(0, templateLines.length - 1);
                    }
                    file.contents = new Buffer(srcLines.join(srcNLReg));
                    break;
            }
            return false;
        } else if (matchPer === 1) {
            return true;
        }
    }
1359020
protected function getMatchers()
    {
        // @todo change to dynamic
        return [
            Matchers\DateMatch::class,
            Matchers\DigitMatch::class,
            Matchers\L33tMatch::class,
            Matchers\RepeatMatch::class,
            Matchers\SequenceMatch::class,
            Matchers\SpatialMatch::class,
            Matchers\YearMatch::class,
            Matchers\DictionaryMatch::class,
        ];
    }
152266
function matchAll(exp, text) {
    exp.lastIndex = 0;
    var matches = [];
    var match;
    while ((match = exp.exec(text)) != null) {
        matches.push(match[0]);
    }
    return matches;
}