DEV Community

Devanshu Biswas
Devanshu Biswas

Posted on

I Built a Live Regex Tester on the Browser's RegExp Engine

Regex looks like line noise until you can see it match. So here's a regex tester that highlights matches live, lists your capture groups, and runs entirely on the browser's built-in engine — no library.

🔎 Try it (type a pattern): https://dev48v.infy.uk/solve/day14-regex-tester.html

The engine is already in your browser

new RegExp(pattern, flags) + string.matchAll(re) gives you every match with its index and capture groups. The whole tool is a thin UI over that.

What it shows live

  • Every match highlighted in the test text as you type
  • Match count + each match's index
  • Numbered AND named capture groups ((?<year>\d{4}))
  • A friendly error (not a crash) when the pattern is invalid — wrap new RegExp in try/catch
  • Flag toggles: g, i, m, s, u

Two gotchas worth knowing

  1. With the global flag, a zero-width match (like a*) can loop forever — bump lastIndex when a match is empty.
  2. Catastrophic backtracking (nested quantifiers like (a+)+) can hang the engine. Keep patterns specific.

🔨 Full build (RegExp + matchAll → highlight → list groups → presets → error handling) on the page: https://dev48v.infy.uk/solve/day14-regex-tester.html

Part of SolveFromZero. 🌐 https://dev48v.infy.uk

Top comments (0)