Regex Tester
Write a JavaScript regular expression, choose its flags, and test it against real sample text without sending either one to a server. The result lists every match's value and character position, plus captured groups when your pattern uses them. Invalid syntax is reported immediately, which makes this useful for a small debugging check before a pattern goes into a validator, log parser, or application.
Use this without the search next time. Prathom Workbench puts Prathom's tools in your toolbar.
Add to Chrome — freeWhat it does
- JavaScript regular expression syntax
- Match values and zero-based positions
- Capture group inspection
- Flag support including global and case-insensitive matching
- Local execution with no uploaded test data
How to use Regex Tester
- 1
Enter the pattern
Type the expression without slash delimiters. For example, use backslash-b for a word boundary and put the flags in their separate field.
- 2
Set the flags
Add g for all matches, i for case-insensitive matching, m for line anchors, or another flag supported by the browser's JavaScript engine.
- 3
Paste test text
Use a small but realistic sample containing both matches and near-misses. The match list updates as the pattern or text changes.
- 4
Inspect the result
Check the match count, zero-based position, and capture groups before copying a pattern into code.
How it works
The component constructs a native RegExp from the pattern and flags whenever either field changes. If construction throws, the message is shown as an invalid-pattern notice and no match is fabricated. For global or sticky expressions, the text is traversed with matchAll; for an ordinary expression, the first exec result is shown because that is the behavior the same pattern will have in ordinary JavaScript code.
Each result keeps the complete match, its zero-based index, and the values captured by parentheses. The tool does not colorize every character or rewrite the expression. A compact match list is easier to copy into a test case and exposes the difference between the full match and a group that extracts only one part.
What it cannot prove
A successful match is not proof that the expression is a good validator. It only says that this engine found text matching this pattern in this sample. Test empty strings, punctuation, Unicode, line endings, malformed input, and realistic maximum lengths before shipping. For security-sensitive validation, combine a regex with a length limit and semantic checks.
The local design is intentional for log fragments, access tokens, customer-shaped fixtures, and source code that should not be uploaded to a random tester. It is not a replacement for unit tests: save important patterns in the project that owns them and run them against a maintained fixture set.
A pattern that passes here can still hang your server
This is the failure worth understanding before you ship any expression, and a tester is exactly where it hides, because the samples you paste in are short.
JavaScript's regex engine backtracks. When a pattern can match the same text more than one way, a failure makes the engine go back and try the alternatives, and for some shapes the number of alternatives grows exponentially with input length. (a+)+$ against a string of forty a characters followed by a ! is the classic demonstration: it never finishes in any time you would wait for.
The shapes to watch are nested quantifiers — a repeated group that itself repeats, like (\s*\w+)* — and alternations where the branches can match the same characters, like (\d|\d\w)+. Both are easy to write by accident when a pattern grows one requirement at a time, and both behave perfectly on the twenty-character example you were thinking about.
Two things make this concrete. Test with input an order of magnitude longer than you expect, and test the near-miss: a string that almost matches, then fails at the very end, is what forces the engine through the whole search space. A pattern that returns instantly on a match and takes a noticeable pause on a failure is telling you something.
If the pattern will ever see input from a user, the durable fixes are structural rather than clever: cap the input length before the regex sees it, avoid nesting quantifiers, and anchor the pattern so failures are found early. Where a pattern is genuinely complex, a hand-written parser is often both faster and easier to read than the expression that replaced it.
Flags change more than they look like they do
The flag field is three or four characters and it decides what the results mean.
g is the one that changes this page's behavior: with it the tool uses matchAll and lists every match, without it you get the first exec result. That mirrors what the same pattern does in your code, which is the point — a .test() call on a g expression carries a lastIndex between calls and will alternate between true and false on identical input, a bug that reads as random flakiness.
m makes ^ and $ match at line breaks rather than only at the ends of the string, which is usually what you want for log parsing and almost never what you want for validating a single value. A pattern anchored with ^...$ and the m flag will happily accept a two-line input where the first line is valid, which is a real way validators get bypassed.
i is simple but worth stating: it applies to the whole pattern, and there is no way to make part of an expression case-insensitive with a flag. Use a character class for the parts that need it.
s makes . match newlines. Without it, . stops at a line break, which is why a pattern that works on one-line samples returns nothing on a real file.
Examples
Find capitalized names
The global flag returns every match, while the word boundaries keep a capitalized fragment inside a larger identifier from being treated as a separate name.
Capture an issue number
The full match is useful for replacement, while the capture group contains only the numeric part that a program might store separately.
Frequently asked questions
Which regular expression flavor does this tester use?
It uses the JavaScript RegExp engine supplied by the browser, including JavaScript flags and capture behavior. It is not PCRE, .NET, Python, or RE2, so a pattern copied from another language may use unsupported escapes or different lookbehind behavior. Test in the same language you plan to run in production.
Why do I only see one match?
JavaScript returns one match by default. Add the g flag to search for every non-overlapping match in the test string. The tester shows up to 100 matches to keep the interface responsive. If the expression is sticky, its matching behavior also depends on the lastIndex position defined by the JavaScript engine.
Are match positions one-based or zero-based?
Positions are zero-based, matching JavaScript string indexes: the first character is position 0. This is the useful convention when you move a match into slice, substring, or replacement code. Newlines and Unicode details can still make visual column counts differ from JavaScript code-unit indexes.
Can a regular expression hang my browser?
Yes. Some nested quantifiers create catastrophic backtracking on carefully chosen input. Keep the sample short while developing a complex pattern, avoid ambiguous nested repetition, and test production-sized strings separately. This page does not execute a worker or promise a time limit around the browser's native RegExp engine.