Regex Linter
Detect error-prone and risky regex patterns, check for catastrophic backtracking, unanchored patterns, and provide rewrite suggestions
## Regex Linter
## Overview
Regex Linter analyzes regular expressions for common anti-patterns, performance issues, and correctness problems. It helps you write better, safer, and more efficient regular expressions.
## Issues Detected
### Critical Issues (Performance)
- **Catastrophic Backtracking**: Nested quantifiers like `(a+)+` that can cause exponential time complexity
- **Quadratic Behavior**: Patterns like `(.*)*` that exhibit O(n²) performance
- **Unbounded Repeats**: Greedy quantifiers without maximum length limits
### Error Issues (Correctness)
- **Unescaped Dots**: Using `. ` when you mean \. (literal dot)
- **Missing Anchors**: Patterns that can match anywhere in the text
- **Invalid Character Classes**: Ranges like `[a-Z]` that include unexpected characters
- **Octal Escapes**: Ambiguous ` ` escapes in modern regex
### Warning Issues (Readability)
- **Observable Non-Greedy**: `.*?` patterns that could use negated character classes
- **Redundant Escapes**: Unnecessary backslashes like `\-`
- **Double Negation**: Confusing `[^[^]]` patterns
- **Ambiguous Alternation**: `a|ab` where order matters
### Info Issues (Style)
- **Non-Capturing Groups**: Suggesting `(?:...)` when groups aren't referenced
- **Verbose Patterns**: Can simplify `ddd` to `d{3}`
## Check Levels
- **basic**: Only critical performance issues
- **standard**: Critical + errors + warnings (recommended)
- **strict**: All issues including style suggestions
## Dialect Support
- **JavaScript**: ES2018+ features including lookbehind and Unicode property escapes
- **Python**: Recommends raw strings, supports verbose regex option
- **PCRE**: Warns about backtracking verbs if used unintentionally
- **Go (RE2)**: Warns about unsupported features (lookbehind, backreferences)
- **Java**: Version-specific feature warnings
## Example
Input:
```regex
(.*+)a
```
Output:
```json
{
"summary": {
"score": 50,
"severity": "error",
"issuesFound": 2
},
"issues": [
{
"severity": "critical",
"message": "Catastrophic backtracking risk",
"suggestion": {
"pattern": "[^a]*a",
"explanation": "Use negated character class instead"
}
}
]
}
```
API Documentation
Request Endpoint
POST /en/api/tools/regex-linter
Request Parameters
| Parameter Name | Type | Required | Description |
|---|---|---|---|
| regexPattern | text | Yes | - |
| regexFlags | text | No | - |
| targetDialect | select | No | - |
| checkLevel | select | No | - |
| includeSuggestions | checkbox | No | - |
Response Format
{
"key": {...},
"metadata": {
"key": "value"
},
"error": "Error message (optional)",
"message": "Notification message (optional)"
}
JSON Data:
JSON Data
AI MCP Documentation
Add this tool to your MCP server configuration:
{
"mcpServers": {
"elysiatools-regex-linter": {
"name": "regex-linter",
"description": "Detect error-prone and risky regex patterns, check for catastrophic backtracking, unanchored patterns, and provide rewrite suggestions",
"baseUrl": "https://elysiatools.com/mcp/sse?toolId=regex-linter",
"command": "",
"args": [],
"env": {},
"isActive": true,
"type": "sse"
}
}
}
You can chain multiple tools, e.g.: `https://elysiatools.com/mcp/sse?toolId=png-to-webp,jpg-to-webp,gif-to-webp`, max 20 tools.
If you encounter any issues, please contact us at [email protected]