{"record":{"id":"4f764fba17a4089a","repo":"oraios/serena","slug":"no-match-found-for-regex-regex","errorCode":null,"errorMessage":"No match found for regex: {regex}","messagePattern":"No match found for regex: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/serena/util/text_utils.py","lineNumber":666,"sourceCode":"    \"\"\"\n\n\ndef find_text_coordinates(content: str, regex: str, require_unique: bool = False) -> TextCoords | None:\n    \"\"\"\n    Finds the line and column number of the first match of a regex pattern in the given content.\n\n    :param content: the text content to search through\n    :param regex: the regular expression pattern to search for; it must match part of a single line,\n        and contain exactly one group that captures the position of interest (e.g., the exact variable name to find the coordinates of)\n    :param require_unique: if True, raises an error if not exactly one match is found;\n        if False, returns None if no match is found, and returns the coordinates of the first match if multiple matches are found\n    :return: the coordinates of the match or None\n    \"\"\"\n    pattern = re.compile(regex, flags=re.MULTILINE | re.DOTALL)\n    matches = list(pattern.finditer(content))\n    if len(matches) == 0:\n        if require_unique:\n            raise ValueError(f\"No match found for regex: {regex}\")\n        return None\n    else:\n        if require_unique and len(matches) > 1:\n            raise ValueError(f\"Match must be unique; found {len(matches)} matches for regex: {regex}\")\n        match = matches[0]\n        if len(match.groups()) != 1:\n            raise ValueError(f\"Regex must contain exactly one group to capture the position, but found {len(match.groups())} groups.\")\n        index_in_content = match.start(1)\n        line, col = TextUtils.get_line_col_from_index(content, index_in_content)\n        return TextCoords(line, col)\n","sourceCodeStart":648,"sourceCodeEnd":677,"githubUrl":"https://github.com/oraios/serena/blob/7fcbca7e62555ec2287ddb2f083caee805848ea6/src/serena/util/text_utils.py#L648-L677","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the current content and update the regex to the actual text","Call with require_unique=False to get None and handle the miss gracefully","Relax the pattern for whitespace/formatting drift","Check you are reading the correct file/revision before locating coordinates"],"exampleFix":"// before\ncoords = find_text_coordinates(content, r'myMethod\\(\\)\\s*\\{')  # renamed method\n// after\ncoords = find_text_coordinates(content, r'(myMethod|renamedMethod)\\(\\)\\s*\\{', require_unique=False)\nif coords is None:\n    raise LookupError('method not found in current source')","handlingStrategy":"validation","validationCode":"if re.search(regex, content, flags=re.MULTILINE|re.DOTALL) is None:\n    return None  # handle miss before calling find_text_coordinates","typeGuard":null,"tryCatchPattern":"try:\n    coords = find_text_coordinates(content, regex)\nexcept ValueError as e:\n    if str(e).startswith('No match found'):\n        coords = None\n    else:\n        raise","preventionTips":["Call with require_unique=False when absence is acceptable","Verify target text exists in the current file/revision","Keep locator patterns in sync with upstream source changes"],"tags":["regex","text-processing","no-match"],"backgroundTag":"pattern-not-found","analyzedSha":"7fcbca7e62555ec2287ddb2f083caee805848ea6","analyzedAt":"2026-08-29T00:04:09.619Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}