opyeb/RegexAudit
ToolGuideFAQ

ReDoS audit · token explainer · code export

A regex that works is not a regex that survives

Paste the pattern, paste the text. RegexAudit scores the pattern for catastrophic backtracking, points at the exact span that can explode, explains every token in plain language and writes the same pattern for JavaScript, Python, Go, Rust or grep. Matching, capture indices, replace, split and extract are here too. No account, no upload, no cookies.

In short

RegexAudit is a free browser tool that audits a regular expression for catastrophic backtracking (ReDoS) and returns a score from 0 to 100, a letter grade from A+ to F, the span inside the pattern that is risky and a rewrite hint. The same page matches text with the browser's own engine, shows every capture group with its index and span, previews replace, split and extract, explains the pattern token by token in four languages and exports it to JavaScript, TypeScript, Python, Go, Rust and PCRE. Everything runs locally in the tab: nothing is uploaded, no account is needed and no cookie or local storage is written.

ReDoS safety audit

100% local

Type a pattern. The audit reads its shape, not your input, and scores how a backtracking engine can be forced to explode.

Pattern library
100/ 100
A+

Matches are painted in the editor and listed below with their index, span and every capture group. Up to 500 matches are kept, and the text is capped at 100,000 characters.

Findings

    Risky spans

    A span is where the finding starts and ends inside the pattern. The grade describes the shape of the pattern only: the same pattern is dangerous or harmless depending on the length and content of the input it is given.

    How it works

    01 / 03
    1. 01

      Paste the pattern and the audit runs

      The audit parses the pattern into groups, classes and quantifiers and looks for the four shapes a backtracking engine cannot finish: nested quantifiers, overlapping alternations, empty branches under a repeat and wildcard chains. You get a score, a grade and the span that carries the risk.

    2. 02

      Read the finding, not only the grade

      Each finding names the shape and the span it covers, with a hint that changes the shape rather than trimming the pattern. A negated class, a required anchor or a single wildcard instead of two usually keeps the meaning and removes the blow-up.

    3. 03

      Check the behaviour, then export

      Paste a real string, read the match table with group indices, try replace, split and extract, and export the pattern to the language you actually ship. Everything happens in the tab, so the pattern never leaves the page.

    Guide

    RegexAudit / ReDoS / export

    What a static ReDoS audit can and cannot tell you

    Catastrophic backtracking is not a bug in a regex engine; it is a property of the pattern meeting an input. A backtracking engine tries alternatives in order and gives up on a branch only after exploring everything under it. When a pattern lets the same characters be divided into the same pieces in many ways, the number of ways grows exponentially with the length of the input, and a string of forty characters can take longer than the age of the universe. That is ReDoS: a regular expression denial of service, and it is reachable from a single text field.

    A static audit reads the shape of the pattern. It can see that (a+)+ allows the inner plus to split a run of a characters in exponentially many ways. It cannot see that your input is always a four-digit year, or that your framework caps the field at twenty characters, which would make the same pattern harmless in practice. So the score is a statement about the pattern, and the length and content of the input decide whether that statement matters. Use it to find patterns that are dangerous by construction, then add the second half yourself: a length cap, a timeout and a test with an input built to defeat the pattern.

    The four shapes that explode

    Nested quantifiers. A group that already repeats without a bound, wrapped in another repeat: (a+)+, (.*)*, (\w+)*, ^(\w+\s?)*$. Every possible split of the run is tried, and the engine only fails after all of them. The rewrite usually removes the inner quantifier: a+ for the first, .* for the second, \w+ for the third, and for the last one an anchor plus a single class such as ^[\w\s]*$. When the inner repetition is genuinely needed, make the outer one bounded ({1,10}) or use a possessive quantifier or an atomic group where the engine supports it ((?>\w+) in PCRE, [\w]++ nowhere in JavaScript: JavaScript has neither, which is why the shape has to change there).

    Overlapping alternatives under a repeat. (a|ab)+ and (a|a?)+ let two branches start with the same character, so the engine can reach the same position by different roads and explores both. The fix is to factor the common prefix: (a|ab)+ becomes a(?:b)? repeated once, or a+b* if that is the real language. When the branches are genuinely different, anchor them so only one can start at a given position, or make the alternation ordered and total (ab|a, longest first).

    An empty branch under a repeat. A group whose alternative can match nothing, repeated without a bound, lets the engine loop without consuming input: (a|)+, (a*)*, (?:a?b?)+ on a long run of b. Remove the empty branch, or make the loop bounded.

    Wildcard chains. Two or more unbounded wildcards in the same sequence: .*.*, .*\s.*\s.*, [^,]*[^,]*. This is quadratic, not exponential, so it survives short inputs and dies on long lines, which makes it the shape that reaches production most often. One wildcard is usually enough, and a negated class that names the terminator ([^\n]*) is cheaper than .* with the s flag.

    Reading the score and the grade

    The score starts at 100. A nested quantifier or an overlapping alternation costs 50, an empty branch under a repeat costs 40, a wildcard chain 25, adjacent unbounded repeats 20, a backreference inside a repeat 15, and the shape-level notes (an unbounded dot, a counted repeat of a thousand or more, four levels of nesting) cost 5 each. The total is clamped to 0. Grades: A+ 98 and above, A 94, A- 90, B+ 86, B 82, B- 78, C+ 74, C 68, C- 62, D 55, F below 55.

    Two words about what the number is not. It is not a runtime measurement: nothing is executed to produce it, so it cannot catch a pattern that is slow because of a large input rather than a pathological shape. And it is not a permission: a pattern graded A+ can still be wrong, and a pattern graded D can be safe behind a twenty-character limit. Read the findings, not the badge. If you need the other half of the answer, the matcher below runs the real engine with a cap of 500 matches, and the test string is capped at 100,000 characters, so a pattern that hangs your browser is caught before it can do damage here; in your own code the equivalent is a timeout around the match.

    The matcher, the flags and the group table

    The matcher uses the browser's own RegExp, so a pattern that works here works in the JavaScript you ship. g finds every match instead of the first; i ignores case; m makes ^ and $ match line boundaries; s lets the dot match a newline; u turns on Unicode mode, where escapes and ranges follow code points; y sticks each attempt to the current position; and d asks the engine for the start and end index of every capture group.

    The table lists each match with its character index, its span, the matched text and every capture group, numbered and named, including groups that did not participate (shown as an empty cell rather than a zero). Group colours in the editor follow the parentheses left to right. This is the part that makes a pattern reviewable: the index tells you whether the engine is looking where you think it is, and the empty group tells you which branch actually fired.

    Replace, split and extract

    Replace follows the JavaScript token rules so the preview and your shipped code agree: $& for the whole match, $1 to $99 for a numbered group, $<name> for a named group, $` for the text before the match, $' for the text after it and $$ for a literal dollar. Without the g flag only the first match is replaced, which is what String.replace does.

    Split divides the text at every match and keeps the capture groups as elements, which is why split(/(\d+)/) returns the numbers and the text between them. Zero-length matches are skipped by the splitter: a match of nothing has no place to divide the string, and treating it as a separator is how splitters end up with an infinite loop. Extract is the one-tab version of the loop everyone writes: pick a group, get one value per match, with missing groups kept as empty cells so the line numbers still line up.

    Exporting to six engines

    JavaScript and TypeScript are the browser's own engine, so the export is the truth. Python's re is close but not identical: named groups are written (?P<name>...), group references (?P=name), and \d, \w and word boundaries are Unicode-aware by default in Python 3, while JavaScript changes them only with the u flag. Go's regexp is RE2: no backreferences, no lookaround, linear time by construction, so a pattern that needs either has to be rebuilt rather than translated. Rust's regex is also linear-time and also refuses backreferences and lookaround. PCRE and grep are the backtracking family: possessive quantifiers and atomic groups exist there, which is where the rewrite hints pay off. None of this is a reason not to use the export: it is a reason to run the exported snippet's tests in the engine you ship.

    Where a regular expression is the wrong tool

    A tool that makes regex easier to read should also say when not to use one. Four cases account for most of the damage.

    • Email addresses. The grammar in RFC 5322 allows comments, quoted strings and nested quoting. Every pattern short enough to read rejects addresses that are legal, and the ones long enough to accept them are unreadable and slow. Check for one @ and a dot, then send a verification mail. That is the only test that proves an address exists.
    • HTML, JSON and other nested formats. A regular expression cannot count nesting, so parsing markup with one produces something that works on your sample and fails on the next page. Use a parser. Regex is fine for extracting one attribute from one known tag; it is not fine for reading a document.
    • Security decisions. A pattern that blocks <script> does not block <script >, and a pattern that allows a safe filename does not stop path traversal once the operating system sees the string. Validate the shape with a pattern if it helps, then escape or reject at the layer that actually decides.
    • Passwords and user input you plan to reject. A length limit plus a check against a list of common passwords beats a character-class regex, and any pattern you run on untrusted input needs a length cap and a timeout, because that is the shape ReDoS arrives in.

    There is a fifth, quieter misuse: trusting a pattern you did not write and did not test. The library below is a starting point, not an authority. Open the audit on a preset, read the findings, and change what does not fit your data before it goes anywhere near production.

    A short workflow that keeps working

    • Audit first. If the grade is below B, change the shape before you tune anything else.
    • Add the input limits the pattern assumes: a maximum length, a timeout around the call, and a rejection path that does not log the whole input.
    • Test with a string built to defeat the pattern, not only with the string it was written for. For ^([a-z]+)+$ that is forty a characters followed by a digit.
    • Export, then run the export's tests in the target engine. Python, Go and Rust differ in ways that show up exactly at the edge cases you care about.
    • Keep the pattern, the audit grade and the test string together in the code review. A regex without its counterexample is a claim, not a test.

    FAQ

    9
    What is ReDoS and why does a regex need an audit?
    ReDoS is regular expression denial of service: a pattern whose backtracking grows exponentially (or quadratically) with the length of the input, so a single request can pin a CPU. It needs no traffic and no exploit, only an input that defeats the pattern. An audit looks for the shapes that cause it before the pattern reaches production.
    Does the score run my pattern against anything?
    No. The audit is static: it reads the pattern and reports the shapes it can see. Nothing is executed to produce the score, so it cannot measure how slow your pattern is on your data. Run the matcher with a long input of your own to see the real timing.
    Why does a pattern graded D still work in my tests?
    Because catastrophic backtracking needs an input built to defeat the pattern. A pattern like ^([a-z]+)+$ is instant on any string that matches, and takes minutes on forty letters followed by one digit. Your tests use strings that match; the attacker does not. Treat the grade as a warning about the shape, not a verdict on the data.
    Which flags does the matcher support?
    The seven JavaScript flags: g (all matches), i (ignore case), m (multiline anchors), s (dot matches newline), u (Unicode mode), y (sticky) and d (group indices). Group indices are read automatically when the browser supports them, so the group table stays exact either way.
    Is the text I paste sent anywhere?
    No. The pattern and the text are evaluated by the JavaScript already in the page. There is no upload, no analytics bundle and no storage write; reloading the page clears everything. The only third-party request is the ad script, which cannot read your input.
    How is the code export different from copying the pattern?
    It writes the declaration, the loop and the group handling the way the target language expects: /pattern/g in JavaScript, re.compile(r'...') in Python, regexp.MustCompile in Go, Regex::new in Rust and a grep -P line for PCRE. It also names the differences that will bite you, such as Go and Rust refusing backreferences and lookaround.
    Can the audit tell me my pattern is correct?
    No. The audit is about safety, and correctness is about the language you meant to describe. A pattern can score 100 and still match the wrong thing. Use the match table with real strings, and keep a counterexample in the test suite for every pattern you keep.
    What happens on a pattern the browser cannot compile?
    The pattern bar reports the position of the mistake and the reason, such as an unterminated group, an unmatched parenthesis, nothing to repeat or an invalid quantifier, instead of the browser's single line. The audit and the matcher stop until the pattern compiles, because a static audit of a broken pattern would only describe a pattern that does not exist.
    How do I report a wrong finding or request a feature?
    Use the contact form linked in the footer. It is the only support channel, so a message cannot get lost between an inbox and a chat thread. A pattern that gets the wrong grade, with the pattern and the expected grade, is the most useful report.