Locate the best instance of 'pattern' in 'text' near 'loc'.

    Args:
      text: The text to search.
      pattern: The pattern to search for.
      loc: The location to search around.

    Returns:
      Best match index or -1.
506078
def match_main(self, text, pattern, loc):
    
    # Check for null inputs.
    if text == None or pattern == None:
      raise ValueError("Null inputs. (match_main)")

    loc = max(0, min(loc, len(text)))
    if text == pattern:
      # Shortcut (potentially not guaranteed by the algorithm)
      return 0
    elif not text:
      # Nothing to match.
      return -1
    elif text[loc:loc + len(pattern)] == pattern:
      # Perfect match at the perfect spot!  (Includes case of null pattern)
      return loc
    else:
      # Do a fuzzy compare.
      match = self.match_bitap(text, pattern, loc)
      return match
425509
def search(self, pattern):
        
        for node in self.nodes.values():
            match, following = pattern.match(self, node)
            if match:
                return match, following
        return [], None
9068
def _find_bracket_position(self, text, bracket_left, bracket_right,
                               pos_quote):
        
        pos = {}
        pstack = []

        for idx, character in enumerate(text):
            if character == bracket_left and \
                    not self.is_char_in_pairs(idx, pos_quote):
                pstack.append(idx)
            elif character == bracket_right and \
                    not self.is_char_in_pairs(idx, pos_quote):
                if len(pstack) == 0:
                    raise IndexError(
                        "No matching closing parens at: " + str(idx))
                pos[pstack.pop()] = idx

        if len(pstack) > 0:
            raise IndexError(
                "No matching opening parens at: " + str(pstack.pop()))

        return pos
1320978
def _sub_patterns(patterns, text):
    
    for pattern, repl in patterns:
        text = re.sub(pattern, repl, text)
    return text
805850
function(match, matchIndex, characterOffset) {

      if (!match[0]) {
        throw new Error('findAndReplaceDOMText cannot handle zero-length matches')
      }
   
      match.endIndex = characterOffset + match.index + match[0].length
      match.startIndex = characterOffset + match.index
      match.index = matchIndex
      return match
    }
661390
def find_in_line(line):  # type: (str) -> Optional[str]
    
    if not line:
        return None

    for method in [find_by_ast, find_version_by_string_lib, find_version_by_regex]:
        by = method(line)
        by = validate_string(by)
        if by:
            return by
    return None
1121932
function locator(value, fromIndex) {
    var result
    var prev

    regex.lastIndex = fromIndex

    result = regex.exec(value)

    if (result) {
      result = regex.lastIndex - result[0].length
      prev = value.charCodeAt(result - 1)

      if (usernameCharacter(prev) || prev === CC_HASH || prev === CC_AT) {
        /* Find the next possible value. */
        return locator(value, regex.lastIndex)
      }

      return result
    }

    return -1
  }
915041
def find(self, pattern):
		
		pos = self.current_segment.data.find(pattern)
		if pos == -1:
			return -1
		return pos + self.current_position
1081199
def parse_body(self, text):
        """"""
        re_raise = re.findall(r'[ \t]raise ([a-zA-Z0-9_]*)', text)
        if len(re_raise) > 0:
            self.raise_list = [x.strip() for x in re_raise]
            # remove duplicates from list while keeping it in the order
            # in python 2.7
            # stackoverflow.com/questions/7961363/removing-duplicates-in-lists
            self.raise_list = list(OrderedDict.fromkeys(self.raise_list))

        re_yield = re.search(r'[ \t]yield ', text)
        if re_yield:
            self.has_yield = True

        # get return value
        pattern_return = r'return |yield '
        line_list = text.split('\n')
        is_found_return = False
        line_return_tmp = ''

        for line in line_list:
            line = line.strip()

            if is_found_return is False:
                if re.match(pattern_return, line):
                    is_found_return = True

            if is_found_return:
                line_return_tmp += line
                # check the integrity of line
                try:
                    pos_quote = self._find_quote_position(line_return_tmp)

                    if line_return_tmp[-1] == '\\':
                        line_return_tmp = line_return_tmp[:-1]
                        continue

                    self._find_bracket_position(line_return_tmp, '(', ')',
                                                pos_quote)
                    self._find_bracket_position(line_return_tmp, '{', '}',
                                                pos_quote)
                    self._find_bracket_position(line_return_tmp, '[', ']',
                                                pos_quote)
                except IndexError:
                    continue

                return_value = re.sub(pattern_return, '', line_return_tmp)
                self.return_value_in_body.append(return_value)

                is_found_return = False
                line_return_tmp = ''
563335
def search(self, text):
        
        key = hash(text)
        searcher = self._searchers.get(key)
        if not searcher:
            searcher = ReverseFileSearcher(self.filename, text)
            self._searchers[key] = searcher

        position = searcher.find()
        if position < 0:
            # reset the searcher to start from the tail again.
            searcher.reset()
            return -1, -1, ''

        # try to get some content from before and after the result's position
        read_before = self.buffer_size / 2
        offset = max(position - read_before, 0)
        bufferpos = position if offset == 0 else read_before
        self.fp.seek(offset)
        return position, bufferpos, self.read()
1086181
def search_previous(self):
        

        pattern = self.get_selected_text() or self.__search_pattern
        if not pattern:
            return False

        return self.search(pattern, **{"case_sensitive": True,
                                       "whole_word": False,
                                       "regular_expressions": False,
                                       "backward_search": True,
                                       "wrap_around": True})
1060834
def get_match_number(self, pattern, case=False, regexp=False):
        """"""
        position = self.textCursor().position()
        source_text = self.get_text(position_from='sof', position_to=position)
        match_number = self.get_number_matches(pattern,
                                               source_text=source_text,
                                               case=case, regexp=regexp)
        return match_number
499217
def search(self, pattern, count=None):
        
        return self._scan(match=pattern, count=count)
519501
def in_string(objet, pattern):
        
        return bool(re.search(pattern, str(objet), flags=re.I)) if objet else False
813895
def find_one(line, lookup):
        
        match = re.search(lookup, line)
        if match:
            if match.group(1):
                return match.group(1)
        return False
359795
def search_next(self):
        

        pattern = self.get_selected_text() or self.__search_pattern
        if not pattern:
            return False

        return self.search(pattern, **{"case_sensitive": True,
                                       "whole_word": False,
                                       "regular_expressions": False,
                                       "backward_search": False,
                                       "wrap_around": True})
1261895
def find(self, text):
        """"""
        for key, value in self:
            if (text in key) or (text in value):
                print(key, value)