Skip to main content
Glama
paladini

devutils-mcp-server

regex_test

Test regular expression patterns against input strings to validate matches, extract groups, and identify positions within text for debugging and development.

Instructions

Test a regular expression pattern against an input string. Returns all matches with groups and indices.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternYesThe regex pattern (without delimiters)
flagsNoRegex flags (default: 'g')g
inputYesThe string to test against

Implementation Reference

  • Implementation of the regex_test tool, which tests a regular expression against a string.
    server.tool(
      "regex_test",
      "Test a regular expression pattern against an input string. Returns all matches with groups and indices.",
      {
        pattern: z.string().describe("The regex pattern (without delimiters)"),
        flags: z
          .string()
          .default("g")
          .describe("Regex flags (default: 'g')"),
        input: z.string().describe("The string to test against"),
      },
      async ({ pattern, flags, input }) => {
        try {
          const regex = new RegExp(pattern, flags);
          const matches: Array<{
            match: string;
            index: number;
            groups: Record<string, string> | null;
          }> = [];
    
          let m;
          if (flags.includes("g")) {
            while ((m = regex.exec(input)) !== null) {
              matches.push({
                match: m[0],
                index: m.index,
                groups: m.groups ? { ...m.groups } : null,
              });
              if (matches.length > 100) break; // Safety limit
            }
          } else {
            m = regex.exec(input);
            if (m) {
              matches.push({
                match: m[0],
                index: m.index,
                groups: m.groups ? { ...m.groups } : null,
              });
            }
          }
    
          const result = {
            pattern,
            flags,
            input_length: input.length,
            matches_found: matches.length,
            matches,
          };
    
          return {
            content: [
              { type: "text" as const, text: JSON.stringify(result, null, 2) },
            ],
          };
        } catch (e) {
          return {
            content: [
              {
                type: "text" as const,
                text: `Error: Invalid regex — ${e instanceof Error ? e.message : String(e)}`,
              },
            ],
            isError: true,
          };
        }
      }
    );

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/paladini/devutils-mcp-server'

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