def find_substr(text: str, substr: str) -> Tuple[str, int]:
    """Locates the substr in the text independent of surface variations.

    Args:
      text: A string that might contain the substr.
      substr: The substr we try to find in the text. If the exact string can't
        be found in the text, the search is repeated ignoring diacritics in the
        text. If the substr contains question marks, these can match any
        character.

    Returns:
      A tuple (found_substr, substr_begin):
      found_substr: A string containing the surface from of the substr as
        found in the text (i.e. possibly with added diacritics, resolved '?'.
      substr_begin: Integer indicating the start position of the substr in the
        text.

    """
    substr_begin = text.find(substr)
    if substr_begin < 0:
      # Try finding the substr in the text without diacritics.
      text_without_diacritics = text
      try:
        text_without_diacritics = HistoryEntry.remove_diacritics(text)
      except ValueError:
        # length changed
        pass
      substr_begin = text_without_diacritics.find(substr)
    if substr_begin < 0:
      regexp_string = substr.replace('?', 'UNKNOWNCHARACTER')
      regexp_string = re.escape(regexp_string)
      regexp_string = regexp_string.replace('UNKNOWNCHARACTER', '.')
      for m in re.finditer(regexp_string, text):
        substr_begin = m.start()
        break
      if substr_begin < 0:
        # match the ? but also remove diacritics
        for m in re.finditer(regexp_string, text_without_diacritics):
          substr_begin = m.start()
          break
    if substr_begin >= 0:  # recover the substr as in the text
      substr = text[substr_begin:substr_begin + len(substr)]
    return substr, substr_begin
Locates the substr in the text independent of surface variations.

    Args:
      text: A string that might contain the substr.
      substr: The substr we try to find in the text. If the exact string can't
        be found in the text, the search is repeated ignoring diacritics in the
        text. If the substr contains question marks, these can match any
        character.

    Returns:
      A tuple (found_substr, substr_begin):
      found_substr: A string containing the surface from of the substr as
        found in the text (i.e. possibly with added diacritics, resolved '?'.
      substr_begin: Integer indicating the start position of the substr in the
        text.

    
language/search_agents/muzero/types.py