# Regex Linter

Detect error-prone and risky regex patterns, check for catastrophic backtracking, unanchored patterns, and provide rewrite suggestions

> Canonical page: https://elysiatools.com/en/tools/regex-linter

- **Category:** Development

- **Keywords:** regex, linter, pattern, validation, performance, security, regular expression

## Overview

## 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"
      }
    }
  ]
}
```

## Inputs

- **Regex Pattern** (text): Enter regex pattern (e.g., ^(a+)+$)...
- **Regex Flags** (text): g, i, m, s, u, y
- **Target Dialect** (select)
- **Check Level** (select)
- **Include Rewrite Suggestions** (checkbox)

## When to use

- When developing or debugging regular expressions to ensure they are efficient and error-free.
- Before deploying regex in production to avoid performance bottlenecks and security risks.
- When learning regex to understand best practices and avoid common pitfalls.

## How it works

- Enter your regex pattern and optional flags in the input fields.
- Select the target dialect (e.g., JavaScript, Python) and check level (basic, standard, strict).
- The tool scans the pattern for issues such as catastrophic backtracking, unescaped characters, and missing anchors.
- Receive a detailed report with severity levels, explanations, and rewrite suggestions if enabled.

## Use cases

- Optimizing regex patterns in web applications to improve response times.
- Validating user input patterns in form fields to prevent injection attacks.
- Reviewing legacy code for regex performance issues during refactoring.

## Frequently asked questions

### What is catastrophic backtracking?

It's a situation where nested quantifiers in a regex can cause exponential time complexity, leading to performance issues or denial-of-service.

### Which regex dialects are supported?

The tool supports JavaScript, Python, PCRE, Go (RE2), and Java, with dialect-specific warnings.

### What does the check level affect?

Basic checks only critical performance issues, standard includes errors and warnings, and strict adds style suggestions.

### Can I get suggestions for fixing issues?

Yes, enable the 'Include Rewrite Suggestions' option to receive optimized pattern alternatives.

### Is this tool suitable for beginners?

Absolutely, it helps identify common mistakes and learn best practices in regex writing.

## Related tools

- [AI Regex Explainer](https://elysiatools.com/en/tools/ai-regex-explainer): Use AI to break down regular expressions into readable explanations
- [Glob to Regex](https://elysiatools.com/en/tools/glob-to-regex): Convert file matching patterns (Glob) to regular expressions
- [Named Group Tester](https://elysiatools.com/en/tools/named-group-tester): Parse and display named capture groups from regex patterns
- [Regex Benchmark](https://elysiatools.com/en/tools/regex-benchmark): Compare performance of different regex patterns, identify bottlenecks, and detect degenerate cases
- [Regex to String Generator](https://elysiatools.com/en/tools/regex-to-string-generator): Generate random strings that match a given regular expression pattern
- [C# Regex Tester (.NET)](https://elysiatools.com/en/tools/csharp-regex-tester): Test .NET/C# regular expressions online with named groups ((?…)), IgnoreCase/Multiline/Singleline options, match highlighting, capture-group tables, a ready-to-paste C# snippet and an IgnorePatternWhitespace preview.
- [Java Regex Tester](https://elysiatools.com/en/tools/java-regex-tester): Test java.util.regex patterns online: (?…) named groups, possessive quantifiers and atomic groups, Pattern flags, ASCII vs UNICODE\_CHARACTER\_CLASS \\d semantics, and ready-to-paste Java code.
- [PCRE2 Regex Tester](https://elysiatools.com/en/tools/pcre-regex-tester): Test PCRE2 patterns online: every named-group syntax ((?P), (?), (\\u0027n\\u0027)), possessive quantifiers, atomic groups, \\A \\z \\h shorthands, plus pcre2grep and C API snippets.

## Samples

- [Regex Pattern Alternatives](https://elysiatools.com/en/samples/regex-alternatives): Multiple ways to write the same regex pattern with different trade-offs in readability, performance, and accuracy
- [Regex Replace Samples](https://elysiatools.com/en/samples/regex-replace): Collection of common and useful regex replacement patterns for text transformation and data cleaning
- [Common Regex Patterns](https://elysiatools.com/en/samples/regex-samples): Commonly used regular expression patterns for validation and matching
- [Risky Regex Patterns](https://elysiatools.com/en/samples/risky-regex): Collection of regex patterns that demonstrate security vulnerabilities, performance issues, and common anti-patterns to avoid

## Related content

- [Regex Testing, Visualization, and Safety Workflow](https://elysiatools.com/en/hubs/regex-utility): Build reliable regular expressions by learning syntax, testing matches, visualizing structure, previewing replacements, benchmarking alternatives, and scanning for ReDoS risk.
