Regex tester

Test and debug regular expressions

All computation runs locally in your browser

Last updated: February 7, 2026
Frank Zhao - Creator
CreatorFrank Zhao
Matches
No match
Highlighted preview
Sample matching text
Regex Diagram

Introduction / overview

The Regex Tester helps you validate a JavaScript regular expression against a block of text. You can toggle common flags, see the match list (including captures and named groups), preview highlighted matches, generate a sample string that matches your pattern, and view a diagram of the regex structure.

The fastest way to debug regex is to make it visual: a match list tells you “what”, and flags + diagram help you see “why”.

If you’re working with tokens or auth headers, you might also find our JWT parser and Basic auth generator helpful.

How to use / quick start

  1. Paste your pattern into “Regex to test”.
  2. Enable the flags you want (for example gg for global matching).
  3. Paste your input into “Text to match”.
  4. Read the match table: index, full match, captures, and named groups.
  5. Use the highlighted preview to spot what actually matched.

Worked example (with indices)

Suppose your text is abc123xyz and your regex is \\d+. The match is 123, starting at index s=3s = 3 and ending ate=6e = 6 (end-exclusive).

LL==ese - s==636 - 3==33

Here LL is the matched length. This is a quick sanity check: the highlighted region should be exactly 3 characters long.

Real-world examples / use cases

Log parsing

Background: you need to extract request IDs. Input: text contains req-1042. Regex: req-(\\d+). Result: capture 1=10421 = 1042.

Quick validation

Background: you want a “rough” email check. Regex: ^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$. Result: match/no-match helps you filter obvious mistakes.

Refactoring text

Background: you’re preparing a search/replace. Use the tester to confirm captures/groups before you apply changes in an editor.

Token inspection

Background: you receive a string that “looks like” a JWT. Regex can detect the three-part structure quickly, then you can decode it with our JWT parser.

Common scenarios / when to use

You need all matches, not just the first

Turn on the global flag (g). Without it, many regex engines stop after the first match.

You’re matching across lines

Use multiline (m) for ^ and $, and singleline (s) when you want . to include newlines.

Your pattern involves Unicode characters

Enable Unicode (u) to treat the pattern as Unicode code points and avoid surprises.

You rely on named groups

Named groups improve readability. The match table shows both numbered captures and named groups.

You’re preparing a risky replace

Use the captures table to confirm group boundaries before making bulk edits.

You want a quick sanity-check

The highlighted preview is the quickest way to confirm that the engine matches what you think it matches.

When it might not be the right tool: if you need PCRE-only features (common in some backend stacks), a JavaScript tester won’t match 1:1. In that case, use the tester that matches your runtime.

Tips & best practices

  • Start narrow, then generalize

    First match a tiny, known substring. Then expand to cover edge cases.

  • Use non-capturing groups when you can

    Prefer (?:...) unless you actually need to capture—it keeps your group numbers stable.

  • Watch for empty matches

    Patterns like .* can match empty strings and behave surprisingly with global matching.

  • Be careful with catastrophic backtracking

    Some patterns become very slow on long inputs. If the regex feels “hangy”, simplify or anchor it.

Calculation method / formula explanation

This tool uses the JavaScript RegExp engine. It runs the pattern against your text and reports: the match index, the matched value, numbered captures, and named groups.

Index model

Each match spans a half-open interval [s,e)[s, e) in the text. The match length is:

L=esL = e - s

The highlighted preview uses the same boundaries, so it’s a direct visual check.

Related concepts / background info

Flags in plain English

  • g: Find all matches (not just the first).

  • i: Ignore case (A equals a).

  • m: ^ and $ treat newlines as boundaries.

  • s: . can match newlines.

  • u: Treat the pattern as Unicode code points.

  • v: Unicode sets mode (newer JS feature).

Frequently asked questions (FAQs)

Why do I only see one match?

Turn on the global flag gg. Without it, many regex operations return only the first match.

Why are my line anchors not working?

Use multiline mm when you expect ^ and$ to work per line.

Why is the diagram blank?

If the pattern is invalid, the visualizer may fail to render. Try simplifying the regex until it displays again.

Will this behave the same as my backend regex?

Not always. This tester uses JavaScript regex behavior. If your backend uses PCRE, .NET, or another engine, some features and edge cases may differ.

Does this tool send my text anywhere?

The calculator runs locally in your browser. Still, avoid pasting secrets into any tool unless you’re comfortable with the risk.

Limitations / disclaimers

Regex behavior differs between engines. Treat these results as JavaScript-specific unless you confirm compatibility. Also, very complex regex patterns can be slow on large inputs.