Skip to content
toolbelt
Back to Guides

Debugging a Regex That Works in Your Head

By ·

Updated

The pattern matches what you expect on one input and silently fails on another. Seeing the captures is how you find out why.

What is this tool?

A regex tester runs a pattern against sample text and shows every match with its capture groups. That visibility is most of the debugging.

How it works

Patterns run in the browser's own regex engine, so behaviour matches JavaScript exactly, including its quirks. Matches are highlighted in place and named groups are listed separately.

Example

Pattern: (?<user>[\w.]+)@(?<host>\w+)\.\w+
Text:    ada@example.com, grace@test.io

user: ada    host: example
user: grace  host: test

When to use it

Whenever you are about to commit a regex. Whenever an existing one fails on a specific string and you cannot see why.

Optimization Tips

The bug is usually greed, not syntax. `\w+` will happily swallow more than you meant; `\w+?` will not. And test with the empty string — a surprising number of patterns crash on it.

Frequently Asked Questions

Which flavour is this?
JavaScript. Its syntax differs from PCRE and Python in several places, especially lookbehind support and named group syntax.
Why does my pattern hang?
Catastrophic backtracking. Nested quantifiers like (a+)+ explode on certain inputs. Simplify the pattern or make it non-greedy.
Can I replace?
Yes, the replace pane shows what a substitution would produce.
Do I need to escape slashes?
Not here, because the pattern is not enclosed in literal slashes.

Ready to try it out?

Put this knowledge into practice with our free tool.

Go to Tool

Related tools