Skip to main content
Glama
rodhayl
by rodhayl

regex_helper

Generate regex patterns from natural language descriptions or explain existing regex patterns to understand their matching behavior.

Instructions

Explain regex or generate regex from natural language.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesAction: explain (explain pattern), generate (create from description)
patternNoFor explain: regex pattern to explain
descriptionNoFor generate: natural language description of what to match
examplesNoFor generate: example strings that should match (optional)
flavorNoRegex flavor (default: javascript)

Implementation Reference

  • Implementation of explainRegex tool handler in CodeAssistanceTools class.
      async explainRegex(
        pattern: string,
        options?: {
          flags?: string;
          generateExamples?: boolean;
        }
      ): Promise<ExplainRegexResult> {
        const flags = options?.flags ?? '';
        const includeExamples = options?.generateExamples ?? true;
    
        const prompt = `You are a regex expert. Explain this regular expression in plain English.
    
    Pattern: ${pattern}
    ${flags ? `Flags: ${flags}` : ''}
    ${includeExamples ? 'Include example matches and non-matches.' : ''}
    
    Provide your response as JSON:
    {
      "pattern": "${pattern}",
      "explanation": "Plain English explanation",
      "breakdown": [
        {"part": "regex part", "meaning": "what it matches"}
      ],
      "examples": [
        {"input": "example text", "matches": true, "matchedPart": "matched portion"}
      ]
    }`;
    
        try {
          const responseText = await this.llmWrapper.callToolLlm(
            'regex_helper',
            [
              { role: 'system', content: prompt },
              { role: 'user', content: `Explain this regex: /${pattern}/${flags}` },
            ],
            { type: 'explain_regex', pattern, flags }
          );
    
          const parsed = this.parseJsonResponse(responseText, {
            pattern,
            explanation: responseText,
            breakdown: [],
            examples: [],
          });
    
          return {
            success: true,
            pattern,
            explanation: parsed.explanation || '',
            breakdown: parsed.breakdown || [],
            examples: parsed.examples || [],
          };
        } catch (error) {
          return {
            success: false,
            pattern,
            explanation: '',
            breakdown: [],
            examples: [],
            error: error instanceof Error ? error.message : 'Unknown error',
          };
        }
      }
  • Implementation of generateRegex tool handler in CodeAssistanceTools class.
      async generateRegex(
        description: string,
        options?: {
          flavor?: 'javascript' | 'python' | 'pcre';
          examples?: string[];
        }
      ): Promise<GenerateRegexResult> {
        const flavor = options?.flavor ?? 'javascript';
    
        const prompt = `You are a regex expert. Generate a regular expression based on this description.
    
    Regex flavor: ${flavor}
    ${options?.examples ? `Examples that should match:\n${options.examples.join('\n')}` : ''}
    
    Provide your response as JSON:
    {
      "pattern": "the regex pattern (without delimiters)",
      "flags": "any flags like 'gi'",
      "explanation": "How the pattern works",
      "examples": [
        {"input": "example", "shouldMatch": true}
      ],
      "alternativePatterns": ["simpler or alternative patterns"]
    }`;
    
        try {
          const responseText = await this.llmWrapper.callToolLlm(
            'regex_helper',
            [
              { role: 'system', content: prompt },
              { role: 'user', content: `Generate a regex that matches: ${description}` },
            ],
            { type: 'generate_regex', flavor }
          );
    
          const parsed = this.parseJsonResponse(responseText, {
            pattern: '',
            explanation: responseText,
            examples: [],
          });
    
          return {
            success: true,
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Zero annotations are provided, so the description carries full disclosure burden. It fails to state whether this tool is read-only, what output format to expect (string explanation? JSON?), error conditions, or side effects. For a computation tool with no annotations, this is a significant transparency gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Extremely efficient single sentence with zero redundancy. Both primary verbs ('Explain', 'generate') are front-loaded, immediately communicating capability without waste.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With rich schema coverage (100%) and clear parameter descriptions, the description doesn't need to document individual params. However, given the lack of output schema and zero annotations, it should disclose return behavior or computational nature. It meets minimum adequacy but leaves gaps regarding output expectations.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, establishing a baseline of 3. The description mentions the two action modes which correspond to the 'action' enum and conditional parameter usage, but adds no syntax details, example formats, or semantic constraints beyond what the schema already documents.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the dual function (explain or generate) and the target resource (regex). However, it doesn't explicitly differentiate from sibling 'code_helper' which might handle regex as part of general coding tasks, stopping it from being a 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The bifurcation into 'explain' vs 'generate' implies usage patterns, but there's no explicit guidance on when to choose this over 'code_helper' or prerequisites (e.g., needing a pattern to explain). It meets the 'implied usage' threshold but lacks explicit when-to-use/when-not-to-use statements.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/rodhayl/mcpLocalHelper'

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