Regex Tester
Test regular expressions against sample text with live match highlighting, capture groups and flag control. Runs entirely in your browser.
Last reviewed by the Radiatus Cloud team
Need this built for your product?
We design, build & host secure software & APIs.
Test against the text that breaks it
The useful workflow for a regular expression is not writing it and hoping. It is assembling sample text that includes the cases you expect to match, the near-misses you expect to reject, and the malformed input you will actually receive, then adjusting the pattern until all three behave. This tester highlights matches live and lists each capture group per match, so a change that quietly breaks group three is visible immediately.
Flags change everything
The global flag makes a pattern find every match rather than the first, and it also gives the regex object mutable state via lastIndex, which is why reusing a global regex across calls to test produces alternating results. That is one of the most confusing bugs in JavaScript. The multiline flag changes ^ and $ to match at line boundaries rather than only string boundaries. The dotAll flag lets . match newlines, which it otherwise never does. The unicode flag enables proper handling of code points beyond the basic plane and is required for \p{...} property escapes.
Greedy versus lazy
Quantifiers are greedy by default: .* consumes as much as possible then backtracks. Matching <.*> against <a>text</a> captures the whole string, not the first tag. Appending ? makes the quantifier lazy so it takes as little as possible. Where practical a negated character class such as [^>]* beats either, because it cannot backtrack across the delimiter and is much faster.
Catastrophic backtracking
Nested quantifiers over overlapping character sets, the classic being (a+)+$, can make the engine explore exponentially many paths on input that fails to match. A pattern that is instant on twenty characters can hang for minutes on thirty. When a regex runs against user-supplied input this is a denial-of-service vector known as ReDoS. Avoid nesting quantifiers, prefer specific character classes over ., and anchor patterns where you can.
Do not parse HTML with regex
HTML is not a regular language. Nesting, optional closing tags, attributes containing angle brackets and comments all defeat any pattern you write. Use a real parser. Regex is right for tokens with a simple, well-defined shape: identifiers, timestamps, hex colours, log line prefixes.
Email validation is a trap
The full RFC 5322 grammar is far more permissive than people expect and a truly conforming pattern is thousands of characters long. For practical purposes check there is exactly one at-sign with something either side and a dot in the domain, then confirm the address by sending mail to it. Delivery is the only real validation.
Related tools
- JSON Formatter — Format and beautify JSON in your browser. Pinpoints syntax errors by line and column, flags unsafe integers, and never uploads your data to a server.
- JSON Validator — Validate JSON syntax with precise line and column errors, and check documents against a JSON Schema. Runs locally in your browser, nothing uploaded.
- HTML Minifier — Minify HTML by removing comments and redundant whitespace, without breaking inline elements or pre blocks. Runs entirely in your browser.
- CSS Minifier — Minify CSS by stripping comments and whitespace safely. Runs in your browser with no upload, and reports the byte saving before and after gzip.
Frequently Asked Questions
Why does my global regex return alternating results?
A regex with the global flag keeps a lastIndex property that advances on each call to test or exec. Reusing the same object gives true, false, true, false on identical input. Create a fresh regex per call, or reset lastIndex to zero before each use.
What is catastrophic backtracking?
When nested quantifiers over overlapping character sets force the engine to explore exponentially many paths on non-matching input. A pattern like (a+)+$ can hang on a few dozen characters. Against user input this is a denial-of-service vector called ReDoS.
What is the difference between greedy and lazy quantifiers?
Greedy quantifiers consume as much as possible then backtrack; lazy ones, written with a trailing question mark, consume as little as possible. Matching <.*> against <a>text</a> takes the whole string, while <.*?> takes just the first tag.
Can I use regex to parse HTML?
Not reliably. HTML is not a regular language: nesting, optional closing tags and attributes containing angle brackets all defeat pattern matching. Use a DOM parser. Regex suits simple well-defined tokens, not structured documents.
Do regex flavours differ between languages?
Yes, significantly. Lookbehind, named group syntax, Unicode property escapes and possessive quantifiers all vary between JavaScript, PCRE, Python, Go and .NET. This tester uses the JavaScript engine, so verify anything you intend to run elsewhere.
Privacy & Security
Your patterns and strings stay in your browser.
How to Use
Enter a JS regex pattern (e.g., /abc/i) and test string to see matches.
Disclaimer: This tool is provided "as is" without warranty of any kind. Results are for educational and utility purposes.
Related Tools
JSON Formatter
DeveloperFormat and beautify JSON in your browser. Pinpoints syntax errors by line and column, flags unsafe integers, and never uploads your data to a server.
JSON Validator
DeveloperValidate JSON syntax with precise line and column errors, and check documents against a JSON Schema. Runs locally in your browser, nothing uploaded.
HTML Minifier
DeveloperMinify HTML by removing comments and redundant whitespace, without breaking inline elements or pre blocks. Runs entirely in your browser.