I built a regex tester after debugging the same class of bug in three projects in one month: a pattern that works in testing, then matches far too much once it hits real data with HTML tags, quotes, or repeated delimiters.

The two bugs behind most of it:

  1. Greediness. Take

    HiBye and the pattern <.+>. The + is greedy, so it matches from the first < to the last > in the string, both tags included. Make it lazy with <.+?> and it stops at the first >.
  2. Catastrophic backtracking. A pattern like (a+)+b run against a long string of a's with no trailing b makes the engine try an exponential number of ways to fail. The tab freezes, and if it's in a server request, so does that.

The tester is built around catching both:

  • Live highlighting with multi-color capture groups
  • A token-by-token plain-English explainer
  • A debugger for patterns that match nothing or too much
  • A performance analyzer that flags nested-quantifier shapes before you paste them into production
  • Match, replace and split modes, a visual builder, and a pattern library

It runs on JavaScript's built-in RegExp, so anything that matches here matches in your JS. The flip side is that it isn't a PCRE or Python flavor tester. Everything runs in the browser, so test strings with real log data never leave your machine.

🔗 https://www.forgeplug.com/tools/regex-tester

What's the worst regex bug you've shipped? And would other flavors (PCRE, Python) be useful to you?