# Regex from Examples MCP for AI Agents MCP

> Regex from Examples generates ranked regular expression candidates from input and extraction pairs. It helps you move from raw data to working patterns quickly by analyzing examples you already have. If you're tired of manual regex debugging, this MCP handles the heavy lifting of pattern identification and coverage testing.

## Overview
- **Category:** automation
- **Price:** Free
- **Endpoint:** https://edge.vinkius.com/vk_preview_YGv100v0ig4t94DjJQKuIRFH5YGkMjflm2N34yYi/mcp
- **Tags:** regex, pattern-matching, heuristics, text-analysis, automation

## Description

Writing regular expressions is often a game of trial and error. You have a few examples of what you need to catch, and you spend way too much time guessing which characters to escape and which quantifiers to use. This MCP changes that by letting your AI client do the heavy lifting. Instead of manually crafting a string, you just show your agent the data you're trying to grab, and it uses heuristic analysis to suggest the best candidates right away. It doesn't just give you one option; it ranks them so you can pick the one that balances precision and readability. You can also check if your pattern actually covers all your edge cases or if it's letting things slip through the cracks. It's a huge time saver for anyone who deals with logs, user input validation, or data scraping. You'll find it's a core part of the Vinkius catalog for anyone who needs to turn messy text into structured data without the headache of manual regex engineering. It takes the guesswork out of pattern matching so you can focus on building your application instead of fighting with backslashes and brackets.

## Tools

### analyze_pattern_complexity
Classifies a regex pattern into its structural category. This helps you understand if your pattern is too broad or appropriately specific for your needs.

### evaluate_pattern_coverage
Provides a detailed breakdown of regex performance against your specific examples. You can see exactly which inputs match and which ones fall through the cracks.

### generate_regex_candidates
Analyzes your input-extraction pairs to produce a ranked list of regex candidates. It identifies the best patterns for strings, numbers, dates, and more based on your data.

## Prompt Examples

**Prompt:** 
```
I need a regex for these: 'ID: 12345', 'ID: 67890', 'ID: 00000'. Give me the best one.
```

**Response:** 
```
Based on your examples, here is the best regex candidate:

`^ID:\s\d{5}$` 

It's a high-specificity match for the 'ID:' prefix followed by 5 digits. Would you like to see other ranked options or check its coverage against more examples?
```

**Prompt:** 
```
Does this regex \d+ work for '123', 'abc', and '456'?
```

**Response:** 
```
Here is the coverage breakdown for `\d+` against your examples:

| Input | Match | Status |
| :--- | :--- | :--- |
| '123' | Yes | ✅ |
| 'abc' | No | ❌ |
| '456' | Yes | ✅ |

It successfully matches the numbers but correctly ignores the letters.
```

**Prompt:** 
```
Is this regex [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} too complex?
```

**Response:** 
```
I've analyzed that pattern. It's classified as an EMAIL pattern with HIGH specificity. It's a standard, well-structured regex for catching most common email formats without being overly broad.
```

## Capabilities

### Generate regex from raw text pairs
Turn your example data into a ranked list of regular expression candidates automatically.

### Rank multiple regex options
Get a prioritized list of patterns based on how well they match your specific data.

### Check regex match coverage
See exactly which examples your pattern hits and which ones it misses.

### Identify missed examples
Get a detailed breakdown of specific data points that failed your regex match.

### Classify pattern complexity
Understand if your regex is too broad or appropriately specific for your data type.

## Use Cases

### Scraping inconsistent product prices
A scraper fails because prices have different symbols. The agent uses generate_regex_candidates to find a pattern that handles both $10 and 10.00.

### Validating user emails
A dev needs to check emails but wants to avoid false positives. They use evaluate_pattern_coverage to ensure the regex catches all valid formats.

### Parsing server logs
A sysadmin needs to pull specific error codes. They provide 5 log lines and use generate_regex_candidates to get a clean extraction pattern.

### Data cleaning
A data analyst has a list of mixed phone numbers. They use the MCP to create a regex that standardizes the format for a database.

## Benefits

- Stop manual guessing by using generate_regex_candidates to get ranked options immediately.
- Ensure 100% coverage with evaluate_pattern_coverage to find missed edge cases before they hit production.
- Understand your logic better using analyze_pattern_complexity to see if your regex is too broad or just right.
- Speed up data scraping by quickly creating patterns for emails, dates, and phone numbers from raw text.
- Reduce bugs in form validation by verifying patterns against multiple real-world user inputs.
- Save hours of debugging by getting a ranked list of candidates instead of writing a single regex from scratch.

## How It Works

The bottom line is you stop guessing regex syntax and start using patterns that actually work on your data.

1. Provide your AI client with a list of input and extraction pairs from your dataset.
2. The MCP analyzes these pairs to produce a ranked list of regex candidates.
3. Choose the best candidate or use the coverage tool to verify it against more data.

## Frequently Asked Questions

**How does Regex from Examples help with web scraping?**
It helps you quickly build patterns to extract data from websites. By giving the agent a few examples of the text you want to grab, it generates the regex for you, handling all the tricky escaping and character matching automatically.

**Can I use Regex from Examples to validate user input?**
Yes, it's perfect for that. You can provide examples of valid and invalid inputs to generate a regex that ensures your application only accepts the correct data formats.

**Does Regex from Examples work for log files?**
It's one of the best ways to parse logs. You can feed the agent a few lines of your server logs, and it will generate a pattern to extract specific error codes, timestamps, or IP addresses.

**How do I check if my regex is catching everything it should?**
You can use the coverage tool. Just provide your regex and a list of examples, and the MCP will give you a breakdown of exactly which items matched and which ones were missed.

**Can Regex from Examples generate regex for phone numbers?**
Yes, it can. Because phone numbers often have different formats (dots, dashes, parentheses), providing a few examples allows the MCP to create a regex that handles those variations accurately.

**Is Regex from Examples good for data cleaning?**
Absolutely. It's great for cleaning up messy datasets. You can use it to identify and extract specific patterns from unorganized text, making it much easier to move that data into a structured format.

**How do I generate a regex?**
Use the `generate_regex_candidates` tool with your input and extraction pairs.

**Can it handle email addresses?**
Yes, the engine detects structural patterns like email addresses using `generate_regex_candidates`.

**How do I know if a regex is accurate?**
Use `evaluate_pattern_coverage` to check for matches and misses against your dataset.