Regex Tester Online — Test, Highlight and Replace Safely

Test JavaScript regular expressions with live match highlighting, capture groups, flags and replacement preview. Runs locally in your browser.

100% Client-Side • Your data stays in your browser
How to use & FAQ
Loading tool...

Regex Tester

A regular expression is a compact pattern language for finding, validating and rewriting text. It is used in form validation, log searching, data cleanup, editors, build scripts and nearly every programming language. The same power makes patterns easy to get wrong: a missing escape, an unexpected greedy quantifier or a forgotten flag can match too much, too little or nothing at all. This regex tester lets you type a pattern and sample text and immediately see every match highlighted, with its position, numbered capture groups and named groups listed beside it. The tool uses the JavaScript regular expression engine built into your browser, so results reflect what your front-end code, Node.js scripts and many other JavaScript environments will do. It supports the g, i, m, s and u flags, a replacement mode that previews the rewritten text using references such as $1 and $<name>, and clear error messages when a pattern is invalid. Everything is evaluated locally in your browser. Your pattern and your test text are not uploaded to a server, which matters when you test against logs, emails or customer records.

How to Use This Tool

  1. 01 Type or paste your pattern into the pattern field without the surrounding slashes. For example, enter \d{3}-\d{4} rather than /\d{3}-\d{4}/.
  2. 02 Paste the text you want to search into the test text area. Real samples work best: include lines that should match and a few that should not.
  3. 03 Toggle the flags you need. Use g to find every match, i to ignore letter case, m so ^ and $ work per line, s so the dot matches line breaks, and u for full Unicode handling.
  4. 04 Review the highlighted preview and the match list. Each entry shows the matched text, its start position and every capture group, including named groups.
  5. 05 Switch to replace mode to preview a rewrite with references like $1, $& or $<name>. Copy the output or the pattern once it behaves the way you expect.

How It Works

The tester compiles your pattern with the browser's RegExp constructor and the flags you choose, then runs it against the test text. With the g flag it walks through the text collecting every match; without it, only the first match is reported, just like calling exec once in JavaScript. For each match it records the matched string, the start and end offsets, the numbered groups and any named groups, and it guards against empty matches so a pattern such as a* cannot loop forever. Patterns that backtrack heavily can freeze a page, a problem known as catastrophic backtracking. To keep the page responsive, evaluation runs with limits on input size, the number of matches collected and the time allowed, and it is executed in a background worker that can be cancelled. When a limit is reached you receive a warning instead of a frozen tab, and the matches found so far remain visible. The highlighted preview is built from plain text segments rather than injected HTML, so tags or scripts in your sample are shown literally and never executed. In replace mode the replacement string follows the same rules as String.prototype.replace: $1 to $99 insert numbered groups, $<name> inserts a named group, $& inserts the whole match and $$ inserts a literal dollar sign. With the g flag every match is rewritten; without it only the first. Remember that this tool follows JavaScript syntax. Features such as possessive quantifiers, inline flags in the middle of a pattern or some lookbehind forms in other engines such as PCRE, Python or .NET may behave differently or not be available, so confirm critical patterns in your target language.

Practical Examples

Extract email addresses with named groups

Input
                      Pattern: (?<user>[A-Za-z0-9._%+-]+)@(?<domain>[A-Za-z0-9.-]+\.[A-Za-z]{2,})  Flags: g  Text: Contact [email protected] or [email protected]
                    
Output
                      2 matches: [email protected] (user=ada, domain=example.com) and [email protected] (user=li.team, domain=sample.org)
                    

Named groups label the parts of each match, so the result list is easy to read and the same names can be used in the replacement string.

Reformat a date with a replacement

Input
                      Pattern: (\d{4})-(\d{2})-(\d{2})  Replacement: $3/$2/$1  Text: Released on 2025-03-14
                    
Output
                      Released on 14/03/2025
                    

Each pair of parentheses becomes a numbered group. The replacement reorders the groups, turning an ISO date into a day-first date without touching the surrounding text.

Match line starts with the multiline flag

Input
                      Pattern: ^ERROR.*$  Flags: g, m  Text: INFO ok
ERROR disk full
WARN slow
ERROR timeout
                    
Output
                      2 matches: "ERROR disk full" and "ERROR timeout"
                    

Without the m flag, ^ and $ only match at the start and end of the whole text. With it, they match at every line, which is what you want when scanning logs.

Tips & Best Practices

  • Start with a small sample and add edge cases one at a time, so you can see exactly which change broke or fixed a match.
  • Prefer specific classes such as \d or [A-Za-z] over a bare dot, and avoid nested quantifiers like (a+)+ that can cause catastrophic backtracking.
  • Escape special characters such as . ? + * ( ) [ ] { } | \ ^ $ when you mean them literally.
  • Use the u flag when your text contains emoji or non-Latin letters, and use named groups to keep long patterns readable.
  • A pattern that works on a sample is not proof of correctness for validation. Test hostile and empty inputs, and validate on the server as well.

Frequently Asked Questions

Which regex flavor does this tester use?

It uses the JavaScript (ECMAScript) regular expression engine of your browser. Syntax and behavior match JavaScript and Node.js, but may differ from PCRE, Python, Java or .NET, so double-check patterns you will run in other languages.

Is my text sent to a server?

No. The pattern and the test text are processed locally in your browser. Nothing is uploaded, so you can test with logs or sample data, although you should still avoid pasting secrets into any page you do not control.

What do the g, i, m, s and u flags do?

g finds all matches instead of the first, i ignores letter case, m makes ^ and $ match at each line, s lets the dot match newlines, and u enables full Unicode matching including code points beyond the basic plane.

Why does my pattern stop with a time or match limit warning?

To protect the page from catastrophic backtracking and huge outputs, the tester limits input size, the number of matches and the running time. Simplify nested quantifiers or narrow the pattern, and the warning should disappear.

How do I use capture groups in the replacement?

Use $1, $2 and so on for numbered groups, $<name> for named groups, $& for the whole match and $$ for a literal dollar sign. These follow the behavior of JavaScript String.replace.

Why does my pattern match only once?

Without the g flag, a JavaScript regular expression returns only the first match. Enable the g flag to highlight and list every match in the text.

Related Tools