HandyBench

Regex Tester

Test regex with live match highlighting.

//g

How to use the Regex Tester

  1. 1 Enter your regular expression and flags.
  2. 2 Paste the test string below.
  3. 3 See the match count, every match highlighted live, and each capture group listed.

What this tester does

Your pattern is passed straight to the browser's own JavaScript RegExp engine, so what matches here will match in any JavaScript or TypeScript code on the same browser. The page finds every match in the test string, shows how many there are, highlights each one, and lists the numbered and named capture groups of every match. It has no replace step. To transform text with a pattern, use find and replace, which has a regex option.

Flags

FlagEffect
gGlobal, on by default. Untick it to see only the first match.
iIgnore case
m^ and $ match at each line, not just the whole string
s. also matches line breaks
uUnicode mode: handles characters beyond the basic plane and rejects sloppy escapes
vUnicode sets mode, a stricter upgrade of u (set operations and string properties). Replaces u when ticked. Shown only if your browser supports it.
ySticky: a match must start exactly where the search position is, so with g it finds only back-to-back matches from the start
dMatch indices, accepted for completeness. Shown only if your browser supports it.

Worked example

Pattern \d{4}-\d{2}-\d{2} with the global flag, tested on Due 2024-03-15 and 2025-01-09., reports 2 matches and highlights 2024-03-15 and 2025-01-09. Make it (?<year>\d{4})-(?<month>\d{2}) and the match list shows, for each hit, the full match plus group 1: 2024, group 2: 03 and the named groups year and month. Untick g and only the first match is reported.

Gotchas

  • Type the pattern without slashes. The field shows the surrounding / characters itself, and you should not write /\d+/g or double the backslashes as you would inside a string literal.
  • Other engines differ. A pattern from PCRE, Python or PHP may use possessive quantifiers, atomic groups or inline flags like (?i). JavaScript lacks those, and the tester will report "Invalid regex".
  • Greedy by default. <.+> swallows everything between the first < and the last > on a line. Add ? to make it lazy.
  • Catastrophic backtracking. A nested quantifier such as (a+)+$ on a long near-miss string can take exponential time. Matching runs in a background worker that is stopped after one second, and the page then shows "Pattern took too long" so the tab stays usable. Simplify the pattern or shorten the text.
  • Zero-length matches, such as x*, are counted and can inflate the total. They are listed as (empty) and are not highlighted. At most 5000 matches are counted, and the first 100 are listed.

The regex cheat sheet lists character classes, quantifiers and ready-made patterns that you can paste in and try.

Examples

  • ▸ The pattern \d{4}-\d{2}-\d{2} finds both dates in "Due 2024-03-15 and 2025-01-09."
  • ▸ The pattern ^\w+@\w+\.\w+$ with the m flag matches a simple email on each line.
  • ▸ The pattern (?<year>\d{4})-(?<month>\d{2}) lists the year and month as named groups for every date it finds.

Frequently asked questions

Which regex flavor does it use?

It uses the JavaScript (ECMAScript) regular-expression engine built into your browser, including the flags g, i, m, s, u and y. The d (indices) and v (unicode sets) flags appear when your browser supports them.

What do the flags g, i and m do?

g finds all matches instead of stopping at the first, i makes matching case-insensitive, and m lets ^ and $ match at the start and end of each line rather than the whole string. g is on by default; turn it off to see only the first match. y (sticky) only matches at the exact position where the search starts.

Does it show capture groups?

Yes. Under the highlighted text, each match lists its position, the full match, every numbered group, and named groups written as (?<name>...). A group that did not take part in the match is marked as such.

Why does my regex work in Python or PHP but say "Invalid regex" here?

JavaScript does not support some syntax from other engines, such as possessive quantifiers, atomic groups and inline flags like (?i). Use the flag checkboxes instead, and rewrite the pattern with features JavaScript supports.

What happens if my pattern runs for too long?

Matching runs in a background worker that is stopped after one second, and the page shows "Pattern took too long" instead of freezing. Nested quantifiers such as (a+)+$ can take exponential time on long non-matching text, so simplify the pattern or shorten the test string.

Related guides