Skip to the tool
DevToolBench

Regex Tester

Match, replace and read a regular expression.

up to 500 characters
Flags
up to 20000 characters
Matches
0
Groups
0
Named
0
Characters
0

Matches

Nothing matched yet. Every match will be listed here with the position it starts at and whatever its groups captured.

Replace

What this pattern says

Each piece of the pattern will be explained here, in the order the engine reads it.

The pattern runs on this page, on your machine, with no time limit to stop it. That is why the pattern and the text are capped: an expression with catastrophic backtracking would otherwise freeze the tab, and a frozen tab is a worse answer than a refused input.

Everything runs in your browser. Nothing you type is sent to a server.

Found a bug in this tool? Report it.

Share this tool

Read the pattern, not just the result

A regex tester earns its keep in the moment the pattern almost works. This one shows every match with the position it starts at, what each numbered and named group captured, a preview of a replacement, and — the part most testers leave out — the expression itself broken into tokens with a sentence on what each one does. If you inherited a pattern from a colleague or a search result, that last table is usually the fastest route to understanding it.

The engine is your own browser's. There is no server evaluating anything, which means the behaviour you see is exactly the behaviour you will get in Node or in a script running in a page.

JavaScript is a dialect, not the standard

There is no single regular expression language, and the differences bite in production rather than in a tester. JavaScript has no free-spacing mode, so you cannot break a long pattern across lines with comments the way Perl, Python and PCRE allow. It has no possessive quantifiers and no atomic groups, which are the two tools other engines give you for stopping runaway backtracking. Lookbehind exists and is unrestricted, but only in reasonably recent runtimes.

In the other direction, the u and v flags give you Unicode property escapes that older engines lack, and named groups use pointed brackets where Python uses a different spelling entirely. Copying a pattern between languages is not a copy; it is a translation, and it deserves a test on both sides.

Greedy, lazy, and the difference in one example

Quantifiers take as much as they can and then give characters back until the rest of the pattern fits. Against the text <b>one</b><b>two</b>, the pattern <b>.*</b> matches the entire line, because the star first swallows everything and then retreats only far enough to find a final closing tag. Adding a question mark makes it lazy, so <b>.*?</b> stops at the first closing tag and finds two separate matches.

Neither behaviour is wrong. Greedy is right when you want the outermost pair of delimiters; lazy is right when you want each inner pair. Most bug reports about a pattern matching "too much" are this distinction and nothing else. Turning the flags on and off in the panel above, with the token table open, is a quick way to feel where the boundary sits.

Catastrophic backtracking, and why the input is capped

Some patterns have a cost that explodes. The classic shape is a repeated group that itself repeats, like (a+)+$ run against a long run of the letter a followed by anything else. Each way of dividing those letters between the inner and outer repetition is a distinct path, the number of paths doubles with every extra character, and the engine tries them all before admitting defeat. Twenty-five characters can be milliseconds; thirty-five can be minutes.

Real patterns hit this too, usually where two alternatives can match the same text, and a validator for email addresses or nested quotes is where it shows up most often. The defences are to avoid overlap between alternatives, to prefer a negated character class over a dot, and to test with input longer than the examples you developed against.

Because the expression here runs on the page with nothing able to interrupt it, the pattern is limited to 500 characters and the text to 20,000. That keeps the worst case finite.

Working with the text itself rather than a pattern? The word counter measures it, sort lines reorders it, and remove duplicate lines thins it out.

Frequently asked questions

Which dialect does this tester use?

The JavaScript one, because it is your browser's own engine doing the work rather than a reimplementation. That matters more than it sounds. A pattern that works in grep, in Python or in a PCRE-based editor can behave differently here, and a pattern that works here will behave the same way in Node, Deno and Bun. If your target is PHP, Java or .NET, treat the result as a strong hint rather than a guarantee.

Why is there a limit on the length of the pattern and the text?

Because the expression runs on the same thread that draws the page, with nothing to interrupt it. Some patterns take time that grows exponentially with the input, so a few dozen extra characters can turn a result into a frozen tab. Capping the pattern at 500 characters and the text at 20,000 keeps even the pathological cases finishing, and a refused input is a much better outcome than a page that stops responding.

What does it mean when a group shows as not taking part?

The group is in the pattern but was not used in that particular match, usually because it sits inside an optional section or on the losing side of an alternation. JavaScript reports it as undefined rather than as an empty string, and the difference matters, because an empty string means the group matched nothing while undefined means it never ran. Code that treats the two the same is a common source of quiet bugs.

Does a named group still have a number?

Yes. Naming a group adds a second way to reach it, it does not remove the first, so a pattern with two named groups still numbers them 1 and 2 from left to right. Both are listed for each match here. In a replacement string you can use either form, and mixing them in one template is legal if not especially readable.

Is my test text sent anywhere?

No. The pattern, the flags, the text and the replacement all stay in the tab, and there is no request of any kind behind this page. That is worth knowing before you paste a log extract or a customer file into any regex tester, since the popular ones evaluate the pattern on a server and keep a shareable copy of whatever you typed.

Related tools

Updated