Skip to main content
Glama

build_regex

Generate regular expressions from natural language descriptions for emails, URLs, phones, dates, IPs, and 15+ patterns. Get patterns with JS/Python/TS code snippets and optional test results.

Instructions

Build and test regular expressions from natural language descriptions. Supports emails, URLs, phones, dates, IPs, colors, UUIDs, and 15+ more patterns. Returns the pattern, code snippets in JS/Python/TS, and optional test results.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
descriptionYesWhat to match (e.g., 'email addresses', 'hex color codes', 'semantic versions')
testStringsNoOptional strings to test the regex against
flagsNoRegex flags (default: 'g')g

Implementation Reference

  • Registration and handler implementation for the 'build_regex' tool. It calls the 'regex-builder' endpoint of the Agent Toolbelt API.
    server.registerTool(
      "build_regex",
      {
        title: "Regex Builder & Tester",
        description:
          "Build and test regular expressions from natural language descriptions. " +
          "Supports emails, URLs, phones, dates, IPs, colors, UUIDs, and 15+ more patterns. " +
          "Returns the pattern, code snippets in JS/Python/TS, and optional test results.",
        inputSchema: {
          description: z
            .string()
            .describe("What to match (e.g., 'email addresses', 'hex color codes', 'semantic versions')"),
          testStrings: z
            .array(z.string())
            .optional()
            .describe("Optional strings to test the regex against"),
          flags: z
            .string()
            .default("g")
            .describe("Regex flags (default: 'g')"),
        },
      },
      async ({ description, testStrings, flags }) => {
        const result = await callToolApi("regex-builder", { description, testStrings, flags });
        const data = result as any;
        const r = data.result;
    
        const lines = [
          `**Pattern:** \`${r.regexLiteral}\``,
          `**Description:** ${r.description}`,
          "",
          "**Code snippets:**",
          "```javascript",
          r.codeSnippets.javascript,
          "```",
          "```python",
          r.codeSnippets.python,
          "```",
        ];
    
        if (r.testResults) {
          lines.push("", "**Test results:**");
          for (const t of r.testResults) {
            const status = t.matched ? "✓" : "✗";
            lines.push(`  ${status} "${t.input}" → ${t.matched ? t.matches.join(", ") : "no match"}`);
          }
        }
    
        return {
          content: [{ type: "text" as const, text: lines.join("\n") }],
        };
      }
    );

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/marras0914/agent-toolbelt'

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