find_regex_matches
Locate all regular expression matches with their exact character positions in text. Returns start, end, and match details for precise text analysis.
Instructions
Find all regex matches with positions. Returns list of {start, end, match} dicts.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | ||
| pattern | Yes |
Implementation Reference
- char_index_mcp/server.py:188-188 (registration)Registers the find_regex_matches tool using the @mcp.tool() decorator from FastMCP.@mcp.tool()
- char_index_mcp/server.py:189-205 (handler)The handler function that implements the tool logic: finds all non-overlapping regex matches in the text, returns list of dicts with start index, end index, and matched string. Handles re.error by raising ValueError.def find_regex_matches( text: Annotated[str, "Text to search in"], pattern: Annotated[str, "Regular expression pattern"] ) -> list[dict]: """Find all regex matches with positions. Returns list of {start, end, match} dicts.""" try: matches = [] for match in re.finditer(pattern, text): matches.append({ "start": match.start(), "end": match.end(), "match": match.group() }) return matches except re.error as e: raise ValueError(f"Invalid regex pattern: {e}")
- char_index_mcp/server.py:190-193 (schema)Input schema defined via Annotated types and descriptions, output is list[dict] with match positions.text: Annotated[str, "Text to search in"], pattern: Annotated[str, "Regular expression pattern"] ) -> list[dict]: """Find all regex matches with positions. Returns list of {start, end, match} dicts."""