JavaScript Regex Debugger Examples

Run three JavaScript regex examples for validation, greedy matches, and date replacement. Each opens with its pattern and input already filled in.

Try a debugging example

Validation bug

Pattern
^\d{5}$
Input
90210 90210-1234 abc90210

With the multiline flag, the anchors apply to each line. Only 90210 should match.

Run validation bug example

Greedy match bug

Pattern
<.+>
Input
<strong>one</strong> <em>two</em>

The greedy pattern matches the entire line. Change the pattern to <[^>]+> to match each tag in this sample separately.

Run greedy match bug example

Replacement bug

Pattern
(\d{4})-(\d{2})-(\d{2})
Input
Ship date: 2026-04-17

The replacement should produce Ship date: 04/17/2026. Reorder the group references to see how the output changes.

Run replacement bug example

Regex debugger loop

  1. Start with the smallest input that fails, then paste the exact same text into the tester.
  2. Keep one passing sample and one failing sample visible before changing the pattern.
  3. Change one piece at a time: anchors, groups, character classes, quantifiers, or flags.
  4. Check the full match, capture groups, and match positions after every edit.
  5. Move to replacement mode when the bug involves `$1`, named groups, `$&`, or output formatting.

Bugs a regex debugger should expose

  • The regex matches a substring even though the full value should be validated.
  • A greedy quantifier captures too much text and hides the part that should fail.
  • A multiline sample behaves differently because `^`, `$`, `.`, or the `m` and `s` flags changed the boundary rules.
  • A capture group is empty, shifted, or missing when replacement output depends on it.
  • Unicode input works in one sample but fails when the `u` flag or Unicode-aware classes are required.

JavaScript details to check online

  • Use JavaScript flags deliberately. The `g` flag finds all matches, `i` ignores case, `m` changes line anchors, `s` lets dot cross newlines, `u` enables Unicode mode, and `y` makes matching sticky.
  • Remember that `RegExp.test()` returns true when any substring matches unless the pattern is anchored for full-value validation.
  • Be careful with reused global or sticky regex objects in code because `lastIndex` can change repeated test results.
  • Keep the final sample set so the same regex debugger session can become a JavaScript or TypeScript unit test.

Debug a regex now

Open the live tester to paste the failing input, toggle JavaScript flags, inspect captures, and preview replacement output in one browser session.

Related Pages on Regex Tester

Regex Debugger FAQ

What is a regex debugger?

A regex debugger is a focused workflow for finding why a regular expression matches, fails, overmatches, or produces the wrong replacement output. This page uses the live JavaScript regex tester for that first-pass debugging loop.

Can I test regex online for JavaScript here?

Yes. The tester runs JavaScript's native RegExp engine in the browser, so it is useful for checking frontend, Node.js, and TypeScript regex behavior before adding the same samples to automated tests.

Why does my regex pass online but fail in code?

The usual causes are different input, missing anchors, flag differences, Unicode handling, multiline behavior, replacement backreferences, or reused global and sticky RegExp objects carrying lastIndex state.