Regex Tester

Test JavaScript regular expressions live. See matches highlighted and capture groups listed.

/ /

Highlighted matches

 

Matches & groups

How to use

  1. Type your regex pattern into the field above (no need to wrap it in slashes).
  2. Toggle the flags you want: g for all matches, i for case-insensitive, etc.
  3. Paste or type the test string into the Test string box.
  4. Watch matches highlight in real time; inspect captured groups in the table below.

What does it do?

This tester runs your pattern against the test string using the browser's native RegExp engine — the same one Node.js, Deno, and every browser use. Matches are highlighted inline. Numbered and named capture groups are extracted into a table so you can see exactly what each parenthesised segment caught.

Example

Pattern (with flag g):

\b(\w+)@(\w+\.\w+)\b

Test string:

Contact us at hello@example.com or support@happycoder.dev. Not an email: foo@bar (no TLD).

Matches:

1  hello@example.com        $1: hello    $2: example.com
2  support@happycoder.dev   $1: support  $2: happycoder.dev

foo@bar does not match because \w+\.\w+ requires a dot in the domain.

Why isn't my regex matching?

  • Forgot the g flag. Without it, only the first match is returned. /cat/.exec("cat cat") finds one "cat"; /cat/g finds both.
  • Unescaped metacharacters. example.com matches examplexcom too because . matches any character. Escape it: example\.com.
  • Greedy matching over-consumes. <.*> on <a><b> captures the whole thing. Use lazy <.*?> or <[^>]*> to stop at the first >.
  • Word boundary confusion. \b is a position between a word char and a non-word char. Patterns like \bfoo-bar\b fail because - is already a non-word boundary in the middle.
  • Case mismatch. [a-z]+ will not match Hello. Add the i flag or include [A-Za-z]+.
  • Multiline ^ / $. Without the m flag they only anchor to the whole string, not each line. Turn on m if you are scanning log lines.

Is my data private?

Yes. We don't save any of the patterns or test strings you type here. Nothing is stored, logged, or retained — everything is discarded the moment you close or refresh the tab. There's no record on our side of what you tested. Feel free to verify in your browser's developer tools.

Frequently asked questions

Which regex flavor does this tester use?

JavaScript (ECMAScript) regex, via the browser's built-in RegExp engine. That differs from PCRE (PHP, Perl), Python's re module, and POSIX regex in several ways: no recursion, no possessive quantifiers, named groups use (?<name>...) instead of (?P<name>...), and character-class shorthands like \d are ASCII-only unless you add the u flag.

Does it support lookbehind?

Yes. Lookbehind assertions like (?<=foo)bar and (?<!foo)bar were added in ES2018 and are supported in all current Chromium, Firefox, and Safari builds. If you are targeting very old browsers in production, check caniuse before relying on them — but this tester itself runs them fine.

What do the flags g, i, m, s, and u mean?

g finds every match instead of just the first. i makes matching case-insensitive. m makes ^ and $ match the start and end of each line instead of the whole string. s (dotall) makes . match newlines. u enables full Unicode handling and stricter escape parsing. Pick only the flags you need — g especially changes how many matches you get.

Why is my greedy quantifier matching too much?

Quantifiers like *, +, and {n,} are greedy by default — they match as much as possible and only give back if the rest of the pattern fails. Add a ? to make them lazy: .*? matches as little as possible. Common fix for <a>.*</a> eating across multiple tags: use <a>.*?</a> or the negated class <a>[^<]*</a>.

How do I reference a captured group later in the pattern or replacement?

Inside the pattern, use \1, \2, etc. to match the same text a previous group captured — (\w+)\s+\1 matches repeated words. In a replacement string (not supported in this live tester, but in String.replace) use $1, $2. Named groups use \k<name> inside the pattern and $<name> in replacements.

Why does my regex break when the pattern contains a dot, slash, or parenthesis?

Those are regex metacharacters. To match them literally, escape with a backslash: \. for a dot, \/ for a slash (optional in a new RegExp string, required between /.../ literals), \( and \) for parentheses. The special chars are . * + ? ^ $ { } ( ) | [ ] \ — any of these as literal text need escaping.

Do you save the regex or test text I type here?

No. We don't save the patterns you write or the text you test them against. Everything you type is discarded the moment you close or refresh the tab — no logs, no record on our side of what you matched. If you want extra reassurance, your browser's developer tools will confirm.

Related tools