Regex Tester

Type a JavaScript regular expression and it's matched against your text live — matches are highlighted as you type.

Updated

Test string 0 chars
Matches highlighted

        
Status Enter a pattern Matches — Groups — Flags —

What the tester runs

This tester compiles the pattern you type with JavaScript's own regular-expression engine (new RegExp) and runs it against the text in the left pane. Every match is wrapped in a highlight in the right pane. The readout reports how many matches were found, how many capturing groups the pattern declares, and which flags were actually applied.

There is no Run button. Matching is live: a change to the pattern, the flags, or the test string re-runs immediately. Global scanning is forced on so you see every match, not only the first. If you omit g, the page still adds it. Flags outside the set g i m s u y are ignored.

When a live tester is the right tool

Use it while you are still shaping a pattern, especially one that will later sit in a validator, a log filter, or a match call in JavaScript. It is faster than bouncing between a file and a REPL, and the highlight makes off-by-one mistakes obvious: a greedy .* that swallowed too much, a word boundary that failed on punctuation, a class that missed a digit.

  • Checking that an email or date pattern hits the samples you care about
  • Counting how many times a token appears in a pasted log
  • Seeing whether a capturing group actually captured what you think it did

Worked example: an allow-list pattern with an unescaped dot

A redirect check is supposed to accept only links to example.com and www.example.com. The pattern in the code is ^https://(www.)?example.com. Put it in the pattern field, set flags to m so each line is tested on its own, and paste these four lines as the test string:

https://example.com/login
https://www.example.com/login
https://wwwxexample.com/login
https://example.com.attacker.net/login

Result: 4 matches, Groups 1. All four lines pass, including two that should never get through. The unescaped dot in www. matches any character, so wwwx is accepted. The missing boundary after com lets example.com.attacker.net through, because the pattern only looks at how the string starts.

Now try ^https://(www\.)?example\.com/. Result: 2 matches, https://example.com/ and https://www.example.com/. The escaped dots only match a literal dot, and the required / after the host stops the lookalike domain. Keep the two bad lines as permanent test cases next to the pattern in your code. For URL checks in production, parsing with the URL constructor and comparing hostname exactly is safer than any pattern.

How to use this page

  1. Type the pattern in the Pattern / field. Do not wrap it in slashes. The slashes in the label are decoration. \d+ is a pattern; /\d+/ is not what you want here.
  2. Put flags in the narrow / flags field. Useful ones: i (case-insensitive), m (^ and $ match at line breaks), s (. matches newlines), u (Unicode), y (sticky). g is always on and shows in the Flags cell even if you leave the box empty.
  3. Paste the sample in the left pane labeled Test string. The header shows its character count. Matches appear highlighted on the right as you type.
  4. Read the strip: Status is a match count or No matches or an invalid-regex message. Matches is the number of highlighted spans. Groups is the number of capturing parentheses in the pattern (the maximum seen), not a count of filled groups per match. Flags is the normalized set actually used.
  5. Copy matches copies each matched substring on its own line, not the groups and not the whole test string. Clear wipes the pattern, flags, and both panes.

A pattern that does not compile (an unclosed [, a trailing backslash) empties the highlight pane and puts the engine error in Status. Zero-width matches, such as \b alone, are advanced past so the loop cannot spin forever. There is also a hard cap around 100,000 matches.

Small examples to start from

Two simple emails. Pattern: \b\w+@\w+\.\w+\b. Test string: write to ada@example.com or grace@navy.mil. You get two highlights: ada@example.com and grace@navy.mil. Matches 2, Groups 0. This pattern is a smoke test, not a validator. It misses plus-tags (ada+dev@...) and will not accept a hyphen in the domain the way a real mailbox spec would.

A date with three groups. Pattern: (\d{4})-(\d{2})-(\d{2}). Test string: invoice 2024-03-15 paid; next 2025-01-02. Two highlights, 2024-03-15 and 2025-01-02. Groups reads 3 because of the three pairs of parentheses. Copy matches writes those two full dates, each on a line. It does not write the year, month, and day separately.

Flags that change the result. Pattern hello, flags empty, test string Hello HELLO hello: one match, the last word. Add i in flags: three matches. Pattern ^id with flag m against a two-line string id: 42 then id: 7 matches both line starts. Without m, only the first line matches. Pattern a.b against a then a newline then b matches only if you add s.

Common mistakes

  • Pasting a Python or PCRE pattern that uses (?P<name>...), possessive ++, or \A / \z. This is JavaScript. Named groups of the (?<name>...) form work in modern browsers; the older Python form does not.
  • Forgetting to double backslashes when you later paste the same pattern into a JS string literal. On this page you type the regex source, so one backslash is enough: \d in the box.
  • Expecting Copy matches to export group 1. It exports match[0] only.
  • Writing /foo/gi in the pattern box. The slashes become literal characters and the match fails.

Limits and privacy

It does not replace, split, or show a match-index table. It does not explain the pattern in English. It does not switch engines to PCRE, Python, Go, or Rust. Lookahead and lookbehind work only to the extent your browser JavaScript already supports them. It will not fetch a file to test against; you paste the text.

The pattern and the test string never leave the page. Compilation and matching run in your browser. Closing the tab drops both.

Testing a pattern without this page

You can still smoke-test a JavaScript regular expression in a browser console or Node REPL with new RegExp and String.prototype.match.

  • Write the pattern without surrounding slashes (for example \d+).
  • Choose flags you need (i, m, s, u); use g to see every match.
  • Compile with new RegExp(pattern, flags) and catch syntax errors.
  • Run against a short sample string and list match[0] (and groups if present).
  • Adjust greedy quantifiers or boundaries when the highlight (or match list) is wrong.

Example: Pattern \b\w+@\w+\.\w+\b against write to ada@example.com or grace@navy.mil yields two simple email-shaped matches (a smoke test, not a full validator).

Quick FAQ

Which regex flavor is this?

The browser’s JavaScript RegExp engine — not PCRE, Python, or Rust. Lookahead and Unicode support follow your browser.

Why is matching slow?

Pathological patterns on long text can be expensive. Test on a sample, then move the pattern into your app with limits.

Are my samples uploaded?

No. Matching runs locally in the tab.