We use cookies and similar technologies to enhance your browsing experience, analyze site traffic, and personalize content and ads. By clicking "Accept", you consent to our use of cookies. Learn more in our Privacy Policy.
by Cosmovex
Test regular expressions online with real-time match highlighting. Supports global, case-insensitive, multiline, and dotall flags. View match groups and named capture groups.
Regex Tester is a free tool for building and checking JavaScript regular expressions against your own sample text. You type a pattern and a flags string, paste in some text, and the tool highlights every match as you type. Each capture group is broken out so you can see exactly what your pattern pulled from the text, which is far quicker than guessing in a console and re-running code on each tweak.
It uses the same regex engine that your code will use in the browser, so what you see here is what you get in production. Everything runs in your browser. The patterns and text you paste are never sent to a server or stored anywhere, which makes it safe to test against log lines, config snippets, or anything else you would rather not upload.
The tool has three inputs: the pattern, the flags, and the test string. As you change any of them, matches update live.
\d{4} rather than /\d{4}/.g (find all matches, not just the first), i (case-insensitive), m (^ and $ match at line breaks), and s (. also matches newlines).Matches are highlighted inline in the test string. Below that, every match is listed with its start index, the full matched text, and each capture group by number (and by name, if you used named groups). If the pattern is invalid, you get the engine's error message instead of a silent failure, so you know whether the problem is your syntax or your data.
Say you have lines like:
2026-06-02 14:33:01 [ERROR] payment-service: timeout after 3000ms
You want the date, the level, the service name, and the message. Use named capture groups so the output is readable:
(?<date>\d{4}-\d{2}-\d{2}) \S+ \[(?<level>\w+)\] (?<service>[\w-]+): (?<msg>.+)
With no flags needed for a single line, the match panel shows:
date = 2026-06-02level = ERRORservice = payment-servicemsg = timeout after 3000msIf you paste many lines and add the g and m flags, you'll get one match per line, each with its own groups. This is the fast way to confirm a pattern before dropping it into a parser, because you can see immediately which lines fail to match instead of finding out at runtime.
Regular expressions show up anywhere you need to find or extract structure in text. Typical reasons to reach for this tool:
The live highlighting makes it especially good for the last-mile question that wastes the most time: why isn't this matching the one line I care about?
The single most common regex surprise is greedy matching. By default, *, +, and ? grab as much as they can. Given the text <a><b> and the pattern <.+>, you might expect <a>, but you get the whole <a><b> because .+ consumes everything up to the last >.
Add a ? after the quantifier to make it lazy, so it takes as little as possible:
<.+?>
Now you get <a> and <b> as separate matches (with the g flag). The same applies to *? and ??.
A related fix is to be specific instead of using .. Matching <[^>]+> says "angle bracket, then one or more non-> characters, then a closing bracket," which is both clearer and faster than relying on laziness. When a pattern matches too much, ask whether . is the culprit and whether a negated character class would describe your intent better.
A few behaviours trip people up:
^ and $ are line-aware only with m. Without the m flag, ^ means start of the whole string and $ means the end. Add m to anchor per line.. skips newlines unless you set s. If your data spans lines and a .+ stops short, the s (dotAll) flag is usually the fix.g flag changes more than the count. It also drives match position across calls in code via lastIndex. In this tool you simply see all matches, but remember that a g-flagged regex object is stateful in real JavaScript./.../ literal), you must double the backslashes: \d becomes "\\d".\., a question mark is \?, and so on.No. Type only the pattern body, like `\d{4}-\d{2}`, and put flags in the separate flags field. The surrounding `/.../ ` slashes are JavaScript literal syntax, not part of the pattern itself.
You need the global flag. Add `g` to the flags field and every match in the test string will be found and highlighted.
Add the `i` flag. For example, the pattern `error` with flag `i` will match `Error`, `ERROR`, and `error`.
By default `^` and `$` match only the start and end of the entire string. Add the `m` (multiline) flag to make them match at the start and end of each line.
The dot does not match newline characters unless you enable dotAll mode. Add the `s` flag so `.` also matches line breaks.
Yes. The tool uses the browser's built-in regular expression engine, the same one your JavaScript runs on. One caveat: if you put the pattern in a JS string instead of a `/.../ ` literal, double the backslashes (`\d` becomes `"\\d"`).
No. The pattern and test text are processed entirely in your browser. Nothing is uploaded or stored, so it is safe to paste logs or other sensitive text.
Wrap the parts you want in parentheses to create capture groups, and they appear separately in the match output. Use named groups like `(?<year>\d{4})` to label them for readability.