Regex Tester & Debugger
Test JavaScript regular expressions live with match highlighting, capture groups and replace preview.
Loading Regex Tester & Debugger… If nothing happens, please enable JavaScript.
Frequently asked questions
Is my input sent to a server?
Which regex flavour does this tool use?
When should I use a regex instead of simple string methods?
How is JavaScript regex different from PCRE (Python, PHP, Perl)?
What are the available flags and what do they do?
Is there a limit on how long the test string or pattern can be?
Can I use this to test a replacement pattern?
What is catastrophic backtracking and how do I avoid it?
What is the difference between a capturing and a non-capturing group?
What is a common beginner mistake with regular expressions?
About Regex Tester & Debugger
Regular expressions (regex or regexp) are a formal language for describing patterns in text. The theory traces back to mathematician Stephen Cole Kleene, who formalised the algebra of regular languages in 1956, and to Ken Thompson, who implemented regex in the QED editor and the original Unix tools grep, sed, and awk in the 1960s and 70s. Modern regex engines extend the theoretical foundation with practical features like lookaheads, backreferences, and named capture groups — making them one of the most powerful text-processing tools available in any programming language.
Regular expressions are indispensable for a wide range of real-world tasks. Form validation — checking that an email address, phone number, or postcode matches the expected format — almost universally uses regex. Log parsers extract structured fields from unstructured log lines using capture groups. Code editors and IDEs use regex for find-and-replace across large codebases. Security tools use regex to detect injection patterns and sensitive data leakage. Data transformation pipelines use regex to normalise inconsistent formats. Network device configurations are audited with regex. Understanding and debugging a regex pattern interactively is far faster than running a script repeatedly.
This tester evaluates JavaScript regular expressions against your input in real time, highlighting every match as you type. It lists all capture groups (numbered and named) for each match so you can immediately see what each group captured. A replacement mode lets you type a replacement template and preview the result of String.prototype.replace or replaceAll, with support for $1, $2, and $<name> backreferences. Everything runs entirely in your browser's JavaScript engine — your patterns and input text are never sent to any server.
Regex is notoriously easy to get subtly wrong. A bare dot (.) matches any character including newlines in some modes, not just a literal period. Greedy quantifiers (*, +) will match as much as possible, often capturing more than intended — use lazy versions (*?, +?) to match as little as possible. The ^ and $ anchors match the start and end of the entire string by default; add the multiline flag (m) if you want them to match at line boundaries. Catastrophic backtracking — where a poorly written regex causes exponential matching time on adversarial input — is a real denial-of-service risk in web applications that apply user-supplied patterns to user-supplied text.
From formal language theory to grep
The concept of regular expressions originates in theoretical computer science. In 1956, mathematician Stephen Cole Kleene published a paper describing 'regular events' — sets of strings that could be described by a finite automaton — and introduced the algebraic notation that would become regex syntax. The star operator (*), called the Kleene star, is named after him. At this point, regular expressions were purely a mathematical abstraction with no connection to computing practice.
The leap from theory to tool came in 1968 when Ken Thompson implemented regex search in the QED text editor and then in the Unix tool grep (whose name stands for 'globally search a regular expression and print'). Thompson's key innovation was an efficient algorithm that converted a regular expression into a nondeterministic finite automaton (NFA) and simulated it, guaranteeing linear-time matching with no catastrophic backtracking. Many modern regex engines abandoned Thompson's NFA approach in favour of backtracking engines that support more features (like backreferences) but can exhibit exponential worst-case behaviour.
Today, regular expressions are supported natively in virtually every programming language and text editor. Yet the syntax has splintered into dozens of incompatible flavours — POSIX BRE, POSIX ERE, PCRE, .NET, Java, Python, JavaScript, Ruby — each with subtle differences in syntax and semantics. A regex written for one language will often work in another, but edge cases abound. This fragmentation is why testing a pattern in the specific engine you will actually use is always recommended before deploying it in production.