Regex Tester

See your pattern match — and see which capture group caught what — as you type it.

/

Flags: g global, i ignore case, m multiline, s dot matches newline, u unicode.

0Matches
0Capture groups
Pattern

Match details

#MatchIndexGroups

Replace preview

Runs in your browser. Everything you type or load here is processed locally by JavaScript on this page. Nothing is uploaded to Tooltrusty or to any third party.

What the regex Tester does

A regular expression is a compact language for describing patterns in text, and the fastest way to get one right is to watch it match. This tester compiles your pattern with the browser's own regex engine and highlights every match in the sample text as you type, so a mistake shows up immediately rather than after you deploy it.

Underneath the highlighting, the details table lists each match with its position in the string and the contents of every capture group. Capture groups — the parts of a pattern in parentheses — are what turn a regex from a test into an extraction tool, and seeing exactly what each one caught is usually where the debugging happens. A group that shows an em dash matched nothing, which normally means it was inside an optional section that did not participate.

The flags field controls behaviour that trips people up constantly. Without g, only the first match is found. Without m, the anchors ^ and $ match the start and end of the whole string rather than of each line. Without s, the dot matches any character except a newline. And i makes the whole pattern case-insensitive.

The replace preview at the bottom shows what String.replace would produce, with $1, $2 and so on substituting your capture groups. That is often the real goal — reformatting a list, rewriting a set of URLs, restructuring a log — and being able to preview it on real text before running it over a whole file saves a lot of grief.

This engine is JavaScript's. Most patterns are portable, but if you are writing for PCRE, Python or Go, check the syntax you rely on: lookbehind, named group syntax and some Unicode property escapes differ between engines.

How to use it

  1. Type your pattern in the top field — do not include the surrounding slashes.
  2. Set the flags. g for all matches, i to ignore case, m for line-based anchors.
  3. Paste realistic sample text, including the cases that should not match.
  4. Check the highlighting and the capture-group table, then use the replace preview if you are transforming text.

A worked example

Extracting the parts of an email address:

Pattern:  (\w+)@(\w+)\.(\w{2,})
Flags:    gi

Against the sample text, this matches sales@example.com and captures three groups: $1 = sales, $2 = example, $3 = com. With a replacement of [$1 at $2] the text becomes Contact [sales at example] or [support at tooltrusty]…

Two things this example demonstrates. It correctly ignores not-an-email@ and @nodomain.com, because both are missing a required part. But it also mangles jane.doe@old-domain.co.uk, matching only doe@old — because \w does not include dots or hyphens. That is the single most useful lesson a regex tester teaches: always test against the inputs you expect to fail, not just the ones you expect to pass.

Frequently asked questions

Why does my pattern only find the first match?

The g flag is missing. Without it the engine stops at the first match. Add g to the flags field to find them all.

Why do ^ and $ not match my line starts?

Without the m flag, ^ and $ anchor to the start and end of the entire string, not each line. Add m for line-based anchoring.

Is this the same regex engine as Python or PHP?

No — this uses JavaScript's engine. Common syntax is shared, but named groups, lookbehind support, and Unicode property escapes vary between engines. Test in your target language before relying on an unusual construct.

Can I paste log files or production data in here?

Yes. The pattern and the text are both evaluated in your browser and nothing is transmitted, which matters because the sample text people use for regex work is usually real log output or real records.