Regex tester

Test a JavaScript regular expression against sample text and inspect every match and capture group.

Highlighted matches
Matches & capture groups

What this does

This compiles your pattern into a JavaScript RegExp with the flags you choose and runs it against the test string. Every match is highlighted in place, and a table breaks each match down into its overall text, its start offset, and the contents of every capture group — numbered groups and (?<name>…) named groups alike. Invalid patterns report the engine's own syntax error.

There is no backend. The regex and the text never leave the page, so you can test against real log lines or user data.

Flags, briefly

  • g — find all matches, not just the first.
  • i — case-insensitive.
  • m^ and $ match at line breaks, not just string start/end.
  • s. also matches newline characters.
  • u — treat the pattern as Unicode; needed for \p{...} property escapes and correct handling of astral characters.
  • y — sticky; matches only at lastIndex, useful for tokenisers.

Worked example

Pattern (the default), with the g flag:

(\w+)@(\w+)\.(\w{2,})

Test string:

Contact ada@example.com or grace@dev.io for access.

Two matches. For ada@example.com the groups are 1: ada, 2: example, 3: com; for grace@dev.io they are grace, dev, io. Add the i flag and an address with capital letters would also match. Give the groups names:

(?<user>\w+)@(?<host>\w+)\.(?<tld>\w{2,})

and the table shows group <user>, group <host>, and group <tld> alongside the numbered ones.

Limits and gotchas

  • ECMAScript semantics. Patterns from other languages may need adjustment.
  • Backslashes are literal in the input box. Enter d, not the doubled \d you'd write inside a JavaScript string literal.
  • Empty-match patterns match everywhere; anchor or require a character.
  • Catastrophic backtracking can freeze the tab. Avoid nested quantifiers over overlapping classes.
  • The g flag changes exec behaviour — the tool manages lastIndex for you, but remember that in your own code a shared /g regex is stateful.

Frequently asked questions

Whose regex flavour is this?
JavaScript's (ECMAScript). It is close to PCRE for everyday patterns but differs in details: no possessive quantifiers, no recursion, different Unicode property syntax, lookbehind is supported in modern engines, and named groups use (?<name>...). A pattern copied from a Python or PHP codebase may need small changes.
My pattern with an empty match hangs or floods with matches.
A pattern that can match an empty string (for example a*) will match at every position. This tool advances past zero-length matches and caps the loop, but the result is usually not what you want — anchor the pattern or require at least one character (a+).
Why does group 2 show "undefined"?
That capture group did not participate in the match — commonly because it was inside an alternation ((a)|(b)) and the other branch matched, or inside an optional group that was skipped. Undefined is different from an empty string match; the tool distinguishes them.
Is there a catastrophic-backtracking risk?
Yes, in any regex engine. Nested quantifiers over overlapping character classes (the classic (a+)+$ against a long non-matching string) can take exponential time. Testing here runs on your machine, so a bad pattern freezes your tab rather than a server, but the lesson transfers: restructure the pattern or add anchors.