ToyTools Guide

How to Test a Regular Expression Online

Write a pattern, pick flags, read match indices and capture groups, and keep expensive patterns from freezing the tab.

6 min read Updated Sep 2026

Quick Answer

A regex tester (also called a regular expression tester or online regex tool) lets you try a pattern against sample text and see every match before you ship it. This one uses your browser's JavaScript RegExp engine, lists match indices and capture groups, and can preview a replace with $1 or named groups.

When you need to test regex online, paste a pattern, add regex flags, and drop in a representative string. Matches update live. Expensive shapes are refused, and any run that takes too long is stopped so the tab cannot hang.

Try the Regex Tester →

What Is a Live Regex Matcher?

A regular expression is a compact way to describe a set of strings: digits, email-shaped tokens, log lines, or the word boundaries around a product name. Writing one by eye is easy. Trusting it is harder, because a pattern that looks right can still miss edge cases or capture the wrong slice.

A regex tester is the scratchpad for that trust. You feed it a pattern and some text, then read what actually matched. Indices tell you where. Groups tell you what each pair of parentheses held. A replace preview shows the edited string without touching your real document yet.

How to Test a Regular Expression Online

Start with the smallest text that shows the behaviour you care about. A single log line beats a 10,000-line dump when you are still shaping the pattern. Type the expression between the slashes, set flags, and watch the match list.

Use g when you expect multiple hits (the tester adds it when missing so every match can be listed). Use i for case-insensitive matching, m so ^ and $ apply per line, and s so . can cross newlines. The d flag asks the engine for match indices when you need exact spans.

Example: pattern (?<word>\b\w{4,}\b) with flags g against "The quick brown fox" reports each word of four or more letters, names the group word, and can rewrite matches as [$<word>] in the replace field.

How Capture Groups Work

Parentheses do two jobs. They group parts of the pattern for quantifiers, and they capture the text that matched that part. Numbered groups are $1, $2, and so on in a replacement. Named groups use (?<name>...) in the pattern and $<name> in the replacement.

Optional groups that did not participate show as undefined in the match explain list. That is the usual reason a replace looks fine while a downstream parser still breaks: the group you expected was empty on some hits. Reading the regex match groups under each hit is therefore the point of the tool, not an extra detail.

Which Regex Flavour Is This?

This tester is JavaScript RegExp, not PCRE, not Python's re, and not the Rust regex crate. Most everyday patterns transfer. Lookbehind, named groups, and Unicode property escapes depend on browser support. Constructs that exist only in PCRE (for example recursive patterns) will not compile here, and that is intentional: the goal is to preview what your front-end or Node code will actually do.

Why Some Patterns Are Blocked

Nested quantifiers such as (a+)+ and overlapping alternatives such as (a|ab)+ can force the matcher to explore an exponential number of paths. On the wrong input that freezes the tab. The tester refuses those shapes up front and also kills any run that exceeds a short time budget.

Test text is capped near 20,000 characters for the same reason. If you need to validate a huge corpus, take a representative slice first, then move the proven pattern into your pipeline.

Regex Tester vs Find and Replace

Use this tester when the question is "what does this pattern do?" Use Find and Replace when the question is "change every match in this document." The replace field here is a preview for learning and debugging. Find and Replace is the editor workflow, with match highlighting across the source.

A practical loop: shape the pattern here until groups look right, preview the replace, then paste the same pattern into Find and Replace (with the regex toggle on) to edit the real text. Diff the before and after with Text Compare if you want a second check.

Common Mistakes

Treating a green match count as proof. Three hits can still mean three empty optional groups. Always open the group list under a match before you trust the pattern.

Pasting a PCRE-only construct into a JavaScript regexp tester. Recursive patterns and some lookaround forms that work in PHP will throw a syntax error here, or worse, compile and match differently. Therefore, test in the same flavour you will ship.

Shipping nested quantifiers such as (a+)+ because they "looked fine" on short happy-path input. On crafted text they hang. Prefer tighter classes, and keep the expensive shapes out of production even if a different tool lets them run.

Is My Text Uploaded?

No. Matching and replace both run in your browser. Runs entirely on your device. Nothing is uploaded. That matters when the sample is a production log line, a customer record, or an auth-token-shaped string you should not paste into a stranger's server.

You May Also Need

You may also need

  • Find and ReplaceApply the pattern to edit a full document once it looks right
  • Text CompareDiff original and replaced text to confirm the edit

Next steps

Alternatives

Continue Learning