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
| Name | Required | Description | Default |
|---|---|---|---|
| description | Yes | What to match (e.g., 'email addresses', 'hex color codes', 'semantic versions') | |
| testStrings | No | Optional strings to test the regex against | |
| flags | No | Regex flags (default: 'g') | g |
Implementation Reference
- mcp-server/src/index.ts:233-285 (handler)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") }], }; } );