Start a project

Tool 123 of 194 · Regex

Regex Debugger with Step Trace

Watch a regular expression match one step at a time, see exactly where it backtracks and why, and find patterns that could hang your app.

Regex Debugger with Step Trace at a glanceIllustration: 1, Pattern; 2, processed in your browser; 3, Step trace.Regex Debugger with Step Trace</>1Pattern3Step trace2In yourbrowser
1 Pattern 2 processed on your device 3 Step trace

Regex Debugger with Step Trace

Pattern and test string

    Step through it

    Pattern

    
      

    Test string

    
      
    GroupTextRange

    Groups in the match

    #NameTextRange

    Steps against input length

    01

    What it does

    Runs your JavaScript regex on its own backtracking engine, records every step, and finds catastrophic backtracking by pumping inputs.

    • ECMAScript syntax: groups, named groups, lazy quantifiers, classes, lookaround, back-references
    • Every try, branch, capture and backtrack recorded and replayable
    • Each result checked against your browser's own RegExp
    • Nested and overlapping quantifiers found in the pattern

    02

    Private by design

    Everything happens in your browser. Nothing you type, paste or upload is sent anywhere, and it keeps working offline once the page has loaded.

    03

    What you get

    A step player, capture groups, a ReDoS verdict and a CSV trace, with a Copy and a Download button on every result.

    • Regex
    • JavaScript
    • ReDoS
    • Debugging

    Why it matters

    A regex tester tells you whether a pattern matches. It doesn't tell you how the engine got there, which is what you need when a pattern matches the wrong thing, or takes seconds on one input and microseconds on another. JavaScript's regex engine backtracks: when part of a pattern fails, it goes back and tries the other choices, and some patterns have exponentially many choices.

    This debugger runs your pattern on its own backtracking engine written to the ECMAScript rules, and records every step: each character tried, each branch taken, each capture and each backtrack. You can play the steps, jump to the next backtrack and see the part of the pattern in use. The final result is compared with your browser's own RegExp, so you know the trace is faithful. It also looks for nested and overlapping quantifiers, the cause of catastrophic backtracking (ReDoS), and confirms them by pumping inputs and counting steps.

    How it works

    1. InputA regex and a test string
    2. In your browserEvery attempt, backtrack and capture traced
    3. OutputThe trace, capture groups and a ReDoS check

    Where it fits in a designer's workflow

    1. Plan
    2. Design
    3. Build
    4. Test
    5. Launch
    Finding out why a pattern matches the wrong thing or hangs.

    By the numbers

    Steps to fail ^(\w+\s?)*$ as the input grows4 letters then "!": 296 steps; 6 letters then "!": 1,166 steps; 8 letters then "!": 4,628 steps; 10 letters then "!": 18,458 steps; 12 letters then "!": 73,760 steps; 14 letters then "!": 294,950 steps4 letters then "!"296 steps6 letters then "!"1,166 steps8 letters then "!"4,628 steps10 letters then "!"18,458 steps12 letters then "!"73,760 steps14 letters then "!"294,950 steps
    Counted by this tool's backtracking engine. Each two extra letters multiply the work by about 4: the nested quantifiers let the engine split the same letters between the inner and outer loop in every possible way before it gives up. Browsers, Node.js and most backtracking engines behave the same, which is how one long form field can stall a server (ReDoS). Source: OWASP: Regular expression Denial of Service; MDN: regular expressions.
    Show the numbers as a table
    InputSteps
    4 letters then "!"296
    6 letters then "!"1,166
    8 letters then "!"4,628
    10 letters then "!"18,458
    12 letters then "!"73,760
    14 letters then "!"294,950

    How to use it

    1. Type your pattern and flags, and a test string.
    2. Read the result and the step count.
    3. Step through the trace, or press Next backtrack to jump to where it goes wrong.
    4. If a ReDoS warning appears, make the inner part unambiguous, or use a possessive form like (?=(a+))\1.

    FAQ

    Why does my pattern take so long on some inputs?

    Patterns like (a+)+$ or (\w+\s?)*$ can split the same text in exponentially many ways. When the overall match fails, the engine tries every split before giving up. The debugger shows the step count growing and gives you an input that triggers it.

    Is this the same engine my browser uses?

    No, it's a separate engine that follows the same ECMAScript rules, so it can record each step. Every result is checked against your browser's RegExp, and a difference is flagged. Step counts are this engine's, not V8's, but they grow the same way.

    Which features are supported?

    Everything in ES2018 regex except the v flag: groups, named groups, back-references, lazy quantifiers, lookahead, lookbehind, character classes and the flags i, m, s, u, g and y. Unicode property escapes are checked with your browser for each character.

    What is ReDoS?

    Regular expression denial of service: an attacker sends input that makes a vulnerable pattern backtrack for seconds or minutes, blocking a server's event loop. Patterns that validate user input are the usual target.

    Is my pattern sent anywhere?

    No. Everything runs in your browser.

    Work with me

    Want a site that gets these right?

    I build fast, accessible websites and web apps that pass these checks from day one. Tell me about your project and I'll reply personally with honest next steps.

    All developer tools · Back to leej.uk