Regex Tester Online

Test regular expressions in real time, highlight matches, and view capture groups.

//g
Flags:global ·
TEST STRING0 chars

When a regex tester is the right tool

A regular expression is hard to trust until you see it run against real text: a date, a log line, or a field you want to extract. A tester is for that moment. You enter a pattern, choose flags, paste a test string, and watch the matches update as you type — highlighted in the text, then listed with their starting index and any named groups.

This page uses the JavaScript RegExp engine in your browser. It does not emulate PCRE, Python, or Go, and it does not perform a replacement. If you need to substitute the matches, use Regex Replace.

Use cases

Trying a pattern against a sample string

Before you put a regex into code, paste a few representative lines and see what actually matches. The highlight makes it obvious when the pattern is too greedy or when it misses a second date on the same line.

Extracting named groups

If you write (?<year>\d{4}) and similar named groups, each match row can show those names and values. That is useful when you are about to useexec or a match-all loop in JavaScript and want to confirm the group names first.

Checking flags without editing code

Toggle i to see a case-insensitive match, m so ^ and $ apply per line, s so . matches newlines, or u for Unicode mode. The default is g (global), so every match is listed unless you turn that flag off.

How testing works

As you type, the page constructs new RegExp(pattern, flags). If that fails, the constructor's message is shown and there are no matches. If it succeeds and g is on, the tester calls exec in a loop and records every match, bumping lastIndex when a match is empty so the loop cannot run forever. Without g, only the first match is recorded.

A second pass builds the highlighted copy of the test string. That pass always includes g, even if you turned it off, so later matches can still be marked in the text while the details list stays at one row. Copy Matches writes each listed match on its own line, not the highlight HTML.

Example — a global pattern with named groups
Pattern:  (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})
Flags:    g
Text:     Released 2024-01-15, patched 2024-06-02

Matches:  2024-01-15  (year: "2024", month: "01", day: "15")
          2024-06-02  (year: "2024", month: "06", day: "02")

Both dates match. Each details row shows the full match, its index in the string, and the named groups. A pattern that used only numbered groups such as (\d{4}) would still match, but those groups would not be printed separately.

Example — flags change which matches are listed
Pattern:  hello
Text:     Hello hello

With the i and g flags, both Hello and hello match.
With neither flag, only the second hello matches.
With i and without g, only the first Hello is listed
in the match details, even though highlighting may
still mark later matches.

Flags are part of the test, not decoration. Turn on the ones you will actually use in code, especially g if you expect more than one match in the details list.

What this tool does not do

It does not replace text, split a string, or explain why a pattern failed beyond the constructor error. It does not show numbered capture groups, start/end columns, or a debugger for backtracking. There is no sample button. Nothing is sent to a server. A very large test string or a catastrophic pattern can still make the tab feel slow.

How to use Regex Tester

  1. Enter the pattern between the slashes. Do not include the surrounding / characters in the field itself.
  2. Toggle the flags you need. The default is g. The letters after the second slash show the current set.
  3. Paste a test string. Matches appear in the highlight pane and in the details list as you type.
  4. Copy Matches if you want the matched text, one match per line.

Frequently asked questions

Is this JavaScript regex, or PCRE, Python, or Go?

It uses the JavaScript RegExp engine in your browser. Syntax and flags that work in PCRE, Python, or Go may fail or mean something else here. Lookbehind, Unicode property escapes, and other features depend on what the browser supports.

Which flags can I turn on?

Five JavaScript flags are available: g (global), i (case-insensitive), m (multiline), s (dotAll), and u (unicode). They default to g. There is no y (sticky), d (indices), or v (Unicode sets) toggle. The letters next to the pattern update as you click the flag buttons.

Why does highlighting show more matches than the details list?

The match list follows the flags you chose: without g, only the first match is listed. The highlight pass always adds g so it can mark every match in the text. If you need the list and the highlights to agree, turn g on.

Are numbered capture groups shown?

Not as a separate list. The details row shows the full match, its starting index, and any named groups (the (?<name>...) syntax) when they are present. Numbered groups such as (foo) are part of the match but are not printed one by one.

Does this page replace text, or only test a pattern?

It only tests. There is no substitution field. To replace matches in a string, use the Regex Replace page, which is a different tool.

Is my text sent to a server?

No. The pattern is compiled and run in your browser as you type. Closing the tab discards what you entered. Do not paste secrets or production data if you would not be comfortable with them sitting in memory on this device.

What happens if the pattern is invalid?

The browser’s RegExp constructor throws, and the page shows that error message. No matches are listed until the pattern is valid JavaScript regex.

Related tools and guides

References

  • The JavaScript regular expressions guide on MDN describes the syntax and flags this page uses, including g, i, m, s, and u.
  • RegExp is the constructor that compiles your pattern. An invalid pattern surfaces as the exception message from that constructor.
  • Flavor differences matter. A pattern copied from a Python or PHP example may need changes before it works in JavaScript, especially around lookbehind and Unicode.