Local search in rulesets of exceptions or suffixes
427521
function find_rule_local(gender, name, ruleset, match_whole_word, tags) {
        for (var i = 0; i < ruleset.length; i++) {
            var rule = ruleset[i];
            if (rule.tags) {
                var common_tags = [];
                for (var j = 0; j < rule.tags.length; j++) {
                    var tag = rule.tags[j];
                    if (!contains(tags, tag)) common_tags.push(tag);
                }
                if (!common_tags.length) continue;
            }
            if (rule.gender !== 'androgynous' && gender !== rule.gender)
                continue;

            name = name.toLowerCase();
            for (var j = 0; j < rule.test.length; j++) {
                var sample = rule.test[j];
                var test = match_whole_word ? name :
                    name.substr(name.length - sample.length);
                if (test === sample) return rule;
            }
        }
        return false;
    }
636370
private boolean matchRuleExceptions(RuleException[] exceptions, CAS aCAS, AnnotationFS annot) {

   // if we have already checked the exceptions for the current match type
   // annotation, return the
   // last result - this can happen in case of MATCH_ALL match strategy
   if (this.lastRuleExceptionAnnotation == annot) {
     return this.lastRuleExceptionMatch;
   }

   // loop over all rule exceptions
   for (int i = 0; i < exceptions.length; i++) {

     // store current match type annotation for performance reason. In case
     // of MATCH_ALL match
     // strategy maybe the matchRuleException() method is called multiple
     // times for the same
     // match type annotations and in that case the result of the rule
     // exception match is exactly
     // the same.
     this.lastRuleExceptionAnnotation = annot;

     // find covering annotation
     AnnotationFS coverFs = findCoverFS(aCAS, annot, exceptions[i].getType());
     // check if covering annotation was found
     if (coverFs != null) {
       // check if the found coverFs annotation match the exception pattern
       if (exceptions[i].matchPattern(coverFs)) {
         this.lastRuleExceptionMatch = true;
         return this.lastRuleExceptionMatch;
       }
     }
   }

   this.lastRuleExceptionMatch = false;
   return false;
 }
442637
def _search_within_pe_warnings(self, matches):
        '''  '''
        pattern = '|'.join(re.escape(match) for match in matches)
        exp = re.compile(pattern)
        if any(exp.search(warning) for warning in self.pefile_handle.get_warnings()):
            return True

        return False
57505
function Rule (subrules, type, handler, props, groupProps, encoding) {
  var self = this
  var n = subrules.length

  this.props = props

  this.debug = false

  // Used for cloning
  this.subrules = subrules

  // Required by Atok#_resolveRules
  for (var p in groupProps)
    this[p] = groupProps[p]

  // Runtime values for continue props
  this.continue = this.props.continue[0]
  this.continueOnFail = this.props.continue[1]

  this.type = type
  this.handler = handler

  // For debug
  this.prevHandler = null
  this.id = this.type !== null ? this.type : handler
  // Id for debug
  this._id = (handler !== null ? (handler.name || '#emit()') : this.type)

  // Subrule pattern index that matched (-1 if only 1 pattern)
  this.idx = -1

  // Single subrule: special case for trimRight
  this.single = (n === 1)

  // First subrule
  var subrule = this.first = n > 0
    ? SubRule.firstSubRule( subrules[0], this.props, encoding, this.single )
    // Special case: no rule given -> passthrough
    : SubRule.emptySubRule

  // Special case: one empty rule -> tokenize whole buffer
  if (n === 1 && subrule.length === 0) {
    subrule = this.first = SubRule.allSubRule
    // Make infinite loop detection ignore this
    this.length = -1
  } else {
    // First subrule pattern length (max of all patterns if many)
    // - used in infinite loop detection
    this.length = this.first.length
  }

  // Instantiate and link the subrules
  // { test: {Function}
  // , next: {SubRule|undefined}
  // }
  var prev = subrule
  // Many subrules or none
  for (var i = 1; i < n; i++) {
    subrule = SubRule.SubRule( subrules[i], this.props, encoding )
    prev.next = subrule
    subrule.prev = prev // Useful in some edge cases
    prev = subrule
    if (this.length < subrule.length) this.length = subrule.length
  }

  // Last subrule (used for trimRight and matched idx)
  this.last = subrule

  // Set the first and last subrules length based on trim properties
  if (!this.props.trimLeft) this.first.length = 0
  if (!this.single && !this.props.trimRight) this.last.length = 0

  this.next = null
  this.nextFail = null
  this.currentRule = null
}
519501
def in_string(objet, pattern):
        
        return bool(re.search(pattern, str(objet), flags=re.I)) if objet else False
1060722
private IndexingRule getApplicableIndexingRule(NodeData state)
   {
      List<IndexingRule> rules = null;
      List<IndexingRule> r = configElements.get(state.getPrimaryTypeName());
      if (r != null)
      {
         rules = new ArrayList<IndexingRule>();
         rules.addAll(r);
      }

      InternalQName[] mixTypes = state.getMixinTypeNames();
      for (InternalQName mixType : mixTypes)
      {
         r = configElements.get(mixType);
         if (r != null)
         {
            if (rules == null)
            {
               rules = new ArrayList<IndexingRule>();
            }
            rules.addAll(r);
         }
      }

      if (rules != null)
      {
         for (IndexingRule ir : rules)
         {
            if (ir.appliesTo(state))
            {
               return ir;
            }
         }
      }

      // no applicable rule
      return null;
   }
1152089
def regexp_filter(self_or_cls, pattern):
        
        def inner_filter(name, p):
            name_match = re.search(pattern,name)
            if name_match is not None:
                return True
            doc_match = re.search(pattern,p.doc)
            if doc_match is not None:
                return True
            return False
        return inner_filter
786320
def __search_iterable(self,
                          obj,
                          item,
                          parent="root",
                          parents_ids=frozenset({})):
        """"""

        for i, thing in enumerate(obj):
            new_parent = "%s[%s]" % (parent, i)
            if self.__skip_this(thing, parent=new_parent):
                continue

            if self.case_sensitive or not isinstance(thing, strings):
                thing_cased = thing
            else:
                thing_cased = thing.lower()

            if thing_cased == item:
                self.__report(
                    report_key='matched_values', key=new_parent, value=thing)
            else:
                item_id = id(thing)
                if parents_ids and item_id in parents_ids:
                    continue
                parents_ids_added = add_to_frozen_set(parents_ids, item_id)
                self.__search(thing, item, "%s[%s]" %
                              (parent, i), parents_ids_added)
958198
def fuzzyfinder(text, collection):
    """"""
    suggestions = []
    if not isinstance(text, six.text_type):
        text = six.u(text)
    pat = '.*?'.join(map(re.escape, text))
    regex = re.compile(pat, flags=re.IGNORECASE)
    for item in collection:
        r = regex.search(item)
        if r:
            suggestions.append((len(r.group()), r.start(), item))

    return (z for _, _, z in sorted(suggestions))
1180855
def substring_search(query, list_of_strings, limit_results=DEFAULT_LIMIT):
    

    matching = []

    query_words = query.split(' ')

    # sort by longest word (higest probability of not finding a match)
    query_words.sort(key=len, reverse=True)

    counter = 0

    for s in list_of_strings:

        target_words = s.split(' ')

        # the anyword searching function is separate
        if(anyword_substring_search(target_words, query_words)):
            matching.append(s)

            # limit results
            counter += 1
            if(counter == limit_results):
                break

    return matching
125498
def _find_attrNS(E, namespaceURI, localName):
    '''
    '''
    try:
        v = E.getAttributeNS(namespaceURI, localName)
        if v: return v
    except: pass
    return None
955793
def locate(self, pattern):
        '''

        '''
        if len(pattern) > len(self):
            raise ValueError('Search pattern longer than searchable ' +
                             'sequence.')
        seq = self.seq

        pattern = str(pattern).upper()
        re_pattern = '(?=' + pattern + ')'
        matches = [index.start() % len(self) for index in
                   re.finditer(re_pattern, seq)]

        return matches
990989
private static final int findKeyword(String s, String[] list) {
        s = PatternProps.trimWhiteSpace(s).toLowerCase(rootLocale);
        for (int i = 0; i < list.length; ++i) {
            if (s.equals(list[i]))
                return i;
        }
        return -1;
    }
653036
def search(lines, pattern):
    
    p = pattern.replace("*", ".*")
    test = re.compile(p)
    result = []
    for l in lines:
        if test.search(l):
            result.append(l)
    return result
1138302
def _apply_search_backrefs(pattern, flags=0):
    """"""

    if isinstance(pattern, (str, bytes)):
        re_verbose = VERBOSE & flags
        if flags & V0:
            re_version = V0
        elif flags & V1:
            re_version = V1
        else:
            re_version = 0
        if not (flags & DEBUG):
            pattern = _cached_search_compile(pattern, re_verbose, re_version, type(pattern))
        else:  # pragma: no cover
            pattern = _bregex_parse._SearchParser(pattern, re_verbose, re_version).parse()
    elif isinstance(pattern, Bregex):
        if flags:
            raise ValueError("Cannot process flags argument with a compiled pattern")
        pattern = pattern._pattern
    elif isinstance(pattern, _REGEX_TYPE):
        if flags:
            raise ValueError("Cannot process flags argument with a compiled pattern!")
    else:
        raise TypeError("Not a string or compiled pattern!")
    return pattern
1220589
def _per_location_tuple_to_step(ir_tuple):
    """"""
    root_block = ir_tuple[0]
    if not isinstance(root_block, root_block_types):
        raise AssertionError(u'Unexpected root block type for MatchStep: '
                             u'{} {}'.format(root_block, ir_tuple))

    coerce_type_block = None
    where_block = None
    as_block = None
    for block in ir_tuple[1:]:
        if isinstance(block, CoerceType):
            if coerce_type_block is not None:
                raise AssertionError(u'Unexpectedly found two blocks eligible for "class" clause: '
                                     u'{} {} {}'.format(block, coerce_type_block, ir_tuple))
            coerce_type_block = block
        elif isinstance(block, MarkLocation):
            if as_block is not None:
                raise AssertionError(u'Unexpectedly found two blocks eligible for "as" clause: '
                                     u'{} {} {}'.format(block, as_block, ir_tuple))
            as_block = block
        elif isinstance(block, Filter):
            if where_block is not None:
                raise AssertionError(u'Unexpectedly found two blocks eligible for "where" clause: '
                                     u'{} {} {}'.format(block, as_block, ir_tuple))

            # Filter always comes before MarkLocation in a given MatchStep.
            if as_block is not None:
                raise AssertionError(u'Unexpectedly found MarkLocation before Filter in '
                                     u'MatchStep: {} {} {}'.format(block, where_block, ir_tuple))

            where_block = block
        else:
            raise AssertionError(u'Unexpected block encountered: {} {}'.format(block, ir_tuple))

    step = MatchStep(root_block=root_block,
                     coerce_type_block=coerce_type_block,
                     where_block=where_block,
                     as_block=as_block)

    # MatchSteps with Backtrack as the root block should only contain MarkLocation,
    # and not do filtering or type coercion.
    if isinstance(root_block, Backtrack):
        if where_block is not None or coerce_type_block is not None:
            raise AssertionError(u'Unexpected blocks in Backtrack-based MatchStep: {}'.format(step))

    return step
615541
function matchIndex(prop) {
    if (!prop || !/\[\d+\]/.test(prop))
        return false;
    var prefix = prop.match(/[^\[]+/i);
    var idx;
    var indices = prop.match(/\d+/g);
    if (!indices)
        return false;
    return {
        name: prefix[0],
        index: indices[0],
        indices: indices.slice(1)
    };
}