Regex Tester
Test JavaScript regular expressions with live highlighting. Runs in your browser.
About this regex tester
This regex tester runs your regular expression against sample text and highlights every match as you type. It uses the JavaScript engine in your browser, so what you see is exactly what your front-end code or Node.js will do.
Below the highlights you get a table of every match with its position and capture groups, named groups included. Switch to Replace to preview String.replace with $1 or $<name>, or to Split to see what String.split returns. A plain-English breakdown explains each token of the pattern, nested by group, and a clickable cheat sheet inserts tokens at your cursor.
Matching runs in a background worker with a 2-second limit. A pattern that backtracks forever gets stopped and explained, and the page stays responsive. Your pattern and test text never leave the browser.
Features
Live highlighting
Matches are marked in alternating colors, so two matches that touch are still easy to tell apart. Empty matches, such as \b or a lookahead, show as a thin red marker.
Capture group table
Every match with its start and end index and each group's value. Named groups show their name. A group that did not take part shows undefined, which is what JavaScript gives you, not an empty string.
All JavaScript flags
g, i, m, s, u, v, y and d as toggles. The u and v flags exclude each other, as they do in the engine. Pasting /pattern/flags offers to split it for you.
Replace and Split previews
Type a replacement with $1, $<name>, $&, $` or $' and see the full result. Split shows each piece, including the empty strings that surprise people.
Plain-English explanation
A tokenizer walks the pattern and describes literals, classes, escapes, anchors, groups, lookarounds, quantifiers (greedy or lazy) and backreferences, indented to show nesting.
Protection from runaway patterns
The match runs off the main thread. If it takes longer than 2 seconds, the worker is stopped and you see why, instead of a frozen tab.
Ready-to-paste code
A JavaScript snippet with the regex literal, flags and the matching call (matchAll, replace or split) for the current view.
How to use the regex tester
- 1Type a pattern and switch on the flags you need, such as g or i.
- 2Paste test text and watch matches highlight, with groups listed in the table.
- 3Switch to Replace or Split, read the explanation, then copy the code.
When to use it
Writing form validation
Check an email, phone or postcode pattern against a list of good and bad examples, one per line, with the m flag and ^ and $ anchors.
Pulling fields out of logs
Use named groups like (?<status>\d{3}) to extract status codes, timestamps or IDs, and read them straight from the group table.
Bulk renaming and reformatting
Swap date formats with a replacement such as $<day>/$<month>/$<year>, then copy the result. For plain-text edits without code, the find and replace tool does the same job with a simpler interface.
Learning regex
Paste a pattern you found online and read the explanation token by token before you trust it in your code.
Debugging a slow pattern
If a pattern times out here, it will hang a server too. Rewrite it until it finishes well under the limit.
How do you test a regex in JavaScript?
In code you write /pattern/flags or new RegExp("pattern", "flags"), then call text.match, re.exec, text.matchAll, text.replace or text.split. Each behaves a little differently. Without the g flag, match and exec return only the first match. With g, matchAll gives every match with its groups, and replace changes every occurrence.
This page mirrors those calls. Match view acts like matchAll with g on, or exec once with g off. Replace view calls replace with your exact replacement string. Split view calls split. Copy the generated snippet and you get the same results in your project.
What do the regex flags g, i, m, s, u, v, y and d do?
Flags change how the whole pattern behaves. These are the ones defined in ECMAScript today:
- g (global): find all matches instead of stopping at the first.
- i (ignore case): A matches a. With u or v, case folding covers Unicode letters too.
- m (multiline): ^ and $ match at the start and end of every line, not only the whole text.
- s (dotAll, ES2018): the dot also matches line breaks.
- u (unicode, ES2015): reads the pattern as code points, enables \u{1F600} and \p{L}, and treats an emoji as one character.
- v (unicodeSets, ES2024): everything u does, plus set operations in classes such as [\p{L}--[a-z]].
- y (sticky): the match must start exactly at lastIndex. Useful for tokenizers.
- d (hasIndices, ES2022): records the start and end of every group in match.indices.
Why does a regex freeze the browser?
JavaScript's regex engine backtracks. When a match fails, it goes back and tries other ways to split the text among the quantifiers. Nested quantifiers like (a+)+ or (.*)* create an exponential number of ways. Run (a+)+$ against 30 letter a's followed by an exclamation mark and the engine tries over a billion combinations before giving up.
This is called catastrophic backtracking, and it has taken real services offline. Fixes usually mean removing the nesting, making the inner part more specific ([^,]+ instead of .*), or anchoring the pattern. This tester stops any match after 2 seconds so you can find the problem safely.
What is the difference between greedy and lazy quantifiers?
Greedy quantifiers (*, +, ?, {n,m}) take as much text as they can, then give some back if the rest of the pattern needs it. Lazy versions add a question mark (*?, +?) and take as little as possible. On the text <b>one</b> <b>two</b>, the pattern <b>.*</b> matches the whole line, while <b>.*?</b> matches each bold tag separately.
Why use Mavros
| Mavros | Typical upload sites | |
|---|---|---|
| Engine | Your browser's own JavaScript RegExp | Sometimes a different engine than the one your code runs |
| Runaway patterns | Stopped after 2 seconds, page stays usable | Tab freezes or crashes |
| Flags | g, i, m, s, u, v, y and d | Usually g, i and m only |
| Named groups | Shown by name in the match table | Numbers only |
| Explanation | Token by token, nested by group | None, or behind an account |
| Privacy | Pattern and text stay on your device | Often sent to a server to save or share |
Tips
- Turn on m and wrap the pattern in ^ and $ to test one candidate per line, such as a list of emails.
- Prefer named groups. $<year> in a replacement is easier to read than $1, and it survives when you add another group in front.
- Escape a literal dot as \. in a pattern. An unescaped dot matches any character, so 1.5 also matches 105.
- Testing a URL pattern? Decode the sample first with the URL decoder, since %20 and a space are different text to a regex.
- Cleaning a list after extracting matches? Remove duplicate lines and then sort the lines.
- Split with a capturing group, like /(,)/, and the separators are kept in the result. Use (?:,) when you do not want them.
Questions
Which regex flavor does this tester use?
JavaScript (ECMAScript), using the RegExp engine built into your browser. Python, PCRE, Java and .NET differ in places, for example in possessive quantifiers and some lookbehind rules.
How do I use named capture groups?
Write (?<name>...) in the pattern. The match table shows the group by name, and in a replacement you refer to it as $<name>. In code, read it from match.groups.name.
Why does my regex match only once?
The g flag is off. Without it, JavaScript stops at the first match. Turn on g to find every match.
What does ?: mean in a regex?
(?:...) is a non-capturing group. It groups items so a quantifier or | applies to them, but it does not save the matched text as a numbered group. It keeps group numbers tidy.
Why did my pattern time out?
It most likely backtracks catastrophically. Nested quantifiers such as (a+)+ or (.*)* make the engine try an exponential number of splits on text that almost matches. Remove the nesting or make the inner part more specific.
Does JavaScript support lookbehind?
Yes, since ES2018. Every current browser supports both (?<=...) and (?<!...), and unlike many other engines JavaScript allows variable-length lookbehind.
How do I match a literal dot, bracket or slash?
Put a backslash in front: \. \[ \( \/. Inside a character class most characters are literal already, so [.] also matches only a dot.
Are my pattern and text saved anywhere?
No. Everything runs in your browser, including the background worker. Nothing is uploaded or stored, and there is no share link.