oraios/serena · error

No match found for regex: {regex}

Error message

No match found for regex: {regex}

What it means

find_text_coordinates() compiles the given regex and, when require_unique is true and no match exists, raises instead of returning None. It is used to locate a captured group's line/column, so an absent match means the target text is not where the caller assumed.

Source

Thrown at src/serena/util/text_utils.py:666

    """


def find_text_coordinates(content: str, regex: str, require_unique: bool = False) -> TextCoords | None:
    """
    Finds the line and column number of the first match of a regex pattern in the given content.

    :param content: the text content to search through
    :param regex: the regular expression pattern to search for; it must match part of a single line,
        and contain exactly one group that captures the position of interest (e.g., the exact variable name to find the coordinates of)
    :param require_unique: if True, raises an error if not exactly one match is found;
        if False, returns None if no match is found, and returns the coordinates of the first match if multiple matches are found
    :return: the coordinates of the match or None
    """
    pattern = re.compile(regex, flags=re.MULTILINE | re.DOTALL)
    matches = list(pattern.finditer(content))
    if len(matches) == 0:
        if require_unique:
            raise ValueError(f"No match found for regex: {regex}")
        return None
    else:
        if require_unique and len(matches) > 1:
            raise ValueError(f"Match must be unique; found {len(matches)} matches for regex: {regex}")
        match = matches[0]
        if len(match.groups()) != 1:
            raise ValueError(f"Regex must contain exactly one group to capture the position, but found {len(match.groups())} groups.")
        index_in_content = match.start(1)
        line, col = TextUtils.get_line_col_from_index(content, index_in_content)
        return TextCoords(line, col)

View on GitHub (pinned to 7fcbca7e62)

Solutions

  1. Verify the current content and update the regex to the actual text
  2. Call with require_unique=False to get None and handle the miss gracefully
  3. Relax the pattern for whitespace/formatting drift
  4. Check you are reading the correct file/revision before locating coordinates

Example fix

// before
coords = find_text_coordinates(content, r'myMethod\(\)\s*\{')  # renamed method
// after
coords = find_text_coordinates(content, r'(myMethod|renamedMethod)\(\)\s*\{', require_unique=False)
if coords is None:
    raise LookupError('method not found in current source')
Defensive patterns

Strategy: validation

Validate before calling

if re.search(regex, content, flags=re.MULTILINE|re.DOTALL) is None:
    return None  # handle miss before calling find_text_coordinates

Try / catch

try:
    coords = find_text_coordinates(content, regex)
except ValueError as e:
    if str(e).startswith('No match found'):
        coords = None
    else:
        raise

Prevention

When it happens

Trigger: Calling find_text_coordinates with a regex that has no match in content while require_unique=True — e.g. locating a template method or property binding that was renamed, removed, or reformatted.

Common situations: Test tooling pointing at source that changed between framework versions; multi-line code reformatting breaking the pattern; file loaded from a different revision than expected.

Related errors


AI-assisted analysis of oraios/serena@7fcbca7e62 (2026-08-29). Data as JSON: /api/errors/4f764fba17a4089a. Report an issue: GitHub.