Skip to main content
Glama

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
NameRequiredDescriptionDefault
textYes
patternYes

Implementation Reference

  • Registers the find_regex_matches tool using the @mcp.tool() decorator from FastMCP.
    @mcp.tool()
  • 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}")
  • 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."""

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/agent-hanju/char-index-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server