Test regular expressions live
Master pattern matching algorithms, state machines, and the security risks associated with catastrophic backtracking.
This tool evaluates Regular Expressions dynamically against your input text. When you type a regex pattern, it compiles it into a Non-deterministic Finite Automaton (NFA) or a Deterministic Finite Automaton (DFA) depending on the browser's underlying JavaScript engine (like V8 for Chrome).
The matching algorithm traverses the input string character by character, attempting to transition through the states of the compiled state machine. Capture groups are preserved in memory to allow backreferencing and structured extraction.
g (global), i (case-insensitive), and m (multiline) modify the state machine behavior.Regex can be a severe security vulnerability known as Regular Expression Denial of Service (ReDoS).
^(a+)+$ applied to the string "aaaaX" will cause the regex engine to try every possible grouping combination before failing, leading to O(2^N) time complexity.A well-written regex executes in O(N) time where N is the length of the string.
However, heavy use of lookaheads (?=...), lookbehinds (?<=...), and nested quantifiers can degrade performance to polynomial or exponential time. In JavaScript, regex evaluation blocks the main thread.
u flag, allowing patterns like \p{Emoji}.Regex bugs are notoriously difficult to spot:
.* will match as much as possible. If you want it to stop at the first match, you must use .*?.. (which matches any character) when you actually meant a literal dot.What is the root cause of Catastrophic Backtracking (ReDoS)?