Regex Tester
Test regular expressions with live match highlighting and capture groups.
const regex = /\b[\w.-]+@[\w.-]+\.\w+\b/gi;
const text = "...";
for (const match of text.matchAll(regex)) {
console.log(match[0], match.index, match.groups);
}How it works
The pattern is compiled with the browser's own RegExp engine, so what you see here is exactly what your JavaScript or TypeScript code will do. The global flag is always applied so that every match is found, not just the first.
Matches are highlighted in the test string as you type, and each one is listed with its index, its numbered capture groups, and any named groups from (?<name>...) syntax. An invalid pattern reports the engine's own syntax error instead of failing silently.
The flags i, m, and s can be toggled: i for case-insensitive matching, m to make ^ and $ match at line boundaries, and s to let the dot match newlines. Results stop at 1,000 matches, which keeps a pattern that matches everything from freezing the page.
Replace mode applies a substitution to every match and shows the result live, with $1 for numbered groups, $<name> for named groups, $& for the whole match, and $$ for a literal dollar sign. The cheat sheet lists the common tokens and inserts any of them into the pattern at the cursor.
The Code panel turns the current pattern, flags, and replacement into a snippet ready to paste into JavaScript, Python, or Go. Named groups and replacement references are translated to each language's syntax, and the Go snippet warns when a pattern uses lookarounds or backreferences, which Go's RE2 engine does not support.
Frequently asked questions
- Which regex flavour does this tester use?
- JavaScript, using the browser's native RegExp. Syntax that only exists in PCRE, Python, or .NET, such as recursive patterns or possessive quantifiers, will not compile here.
- How do I use capture groups?
- Wrap part of the pattern in parentheses and it is captured and listed for each match. Name it with (?<year>\d{4}) to get a named group, which is easier to read than counting positions.
- What do the i, m, and s flags do?
- The i flag ignores case. The m flag makes ^ and $ match at the start and end of each line rather than the whole string. The s flag lets the dot match newline characters too.
- Why do I only see 1,000 matches?
- That is a deliberate cap. A pattern such as .* or an empty match against a large input can produce an unbounded list, so the tester stops there and keeps the page responsive.
- Is my test string sent anywhere?
- No. Compiling and running the pattern happens in your browser and the page makes no network requests, so logs or sample data you paste in stay on your device.
- How do I share a regex with a colleague?
- Click Share link. The pattern, flags, test string, and replacement are stored in the part of the URL after the #, which browsers never send to a server, and opening the link restores them exactly. Leave sensitive data out of the test string before sharing, since anyone with the link can read it.
- Can I use the same regex in Python or Go?
- Usually, with small changes that the Code panel makes for you: Python and Go write named groups as (?P<name>...), Python's re.sub uses \g<1> in the replacement and Go uses ${1}. Go cannot run lookarounds or backreferences at all, and the generated Go code says so when your pattern contains them.