Skip to main content
Glama

find_regex_matches

Locate all regular expression matches with character positions in text. Returns start, end, and match details for precise text analysis and extraction.

Instructions

Find all regex matches with positions. Returns list of {start, end, match} dicts.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes
patternYes

Implementation Reference

  • The main handler function that implements the 'find_regex_matches' tool logic. It uses Python's re.finditer to locate all non-overlapping matches of the given regex pattern in the text and returns a list of dictionaries containing the start index, end index, and matched string for each match. Includes error handling for invalid regex patterns.
    @mcp.tool() 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}")
  • The @mcp.tool() decorator registers the find_regex_matches function as an MCP tool.
    @mcp.tool()
  • Input schema defined via type annotations: text (str), pattern (str). Output: list[dict] with match details.
    text: Annotated[str, "Text to search in"], pattern: Annotated[str, "Regular expression pattern"] ) -> list[dict]:

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