Regex Tester
Test JavaScript regular expressions live: highlighted matches, numbered and named capture groups, all seven flags and a replace preview. Patterns run in a background worker, so a runaway regex can't freeze the page.
Match Preview0 matches
Contact us at support@example.com or sales@company.org.
Release date: 2025-03-14, next review 2025-09-01.
Visit https://stackutils.dev for more tools.
Server IP: 192.168.1.100. Color: #ff6347.What this regex tester does
Regular expressions are compact, but they are also easy to get subtly wrong: a missing anchor matches too much, a greedy quantifier swallows the next field, a group you thought was number 2 is actually number 3. This tester lets you write a JavaScript pattern, paste real sample data and see immediately what matches, where each match starts, and what every capture group contains.
It is built for developers who write validation rules, log parsers, search-and-replace scripts or router patterns in JavaScript or TypeScript. Because it uses the browser's own RegExp engine, there is no translation layer: if a pattern works here, it works in your Node.js or front-end code with the same flags. Every pattern runs inside a Web Worker with a one-second limit, so even a pathological expression cannot lock up the tab.
How to use it
- Type your pattern in the Regular Expression field, without the surrounding slashes. The flags you pick are shown after the closing slash.
- Tick the flags you need: g global, i ignore case, m multiline, s dotAll, u unicode, y sticky and d indices.
- Paste the text you want to search into Test String. Matches are highlighted in Match Preview with alternating colours so adjacent matches stay distinguishable.
- Check Match Details for the index of each match and the value of every group, labelled $1, $2 and with the group name when it has one.
- To test a substitution, enable Replace mode, type a replacement string and copy the result with Copy result. Copy matches copies all matched values, one per line.
Not sure where to start? The Examples buttons load ready-made patterns for emails, URLs, IPv4 addresses, ISO dates and hex colours.
Worked example: rewriting email addresses
Load the Email example. The pattern uses two named groups:
(?<user>[\w.%+-]+)@(?<domain>[\w.-]+\.[a-zA-Z]{2,}) flags: g
Test string:
Contact us at support@example.com or sales@company.org.The tester reports two matches: support@example.com at index 14 (with $1 <user> = support and $2 <domain> = example.com) and sales@company.org at index 37. Notice that the trailing full stop is not included: the engine backtracks so that \.[a-zA-Z]{2,} ends on org. With Replace mode on and the replacement $<user> at $<domain>, the output is:
Contact us at support at example.com or sales at company.org.
What the flags and results mean
- g (global) finds every match. Without it you only see the first one, and Replace mode only replaces the first occurrence.
- i (ignore case) makes /abc/ match ABC.
- m (multiline) makes ^ and $ match at every line break, which you want when validating each line of a log.
- s (dotAll) lets . match newlines too.
- u (unicode) treats the pattern as code points, enables \p{L}-style property escapes and makes invalid escapes an error instead of silently matching a letter.
- y (sticky) anchors each match at the position where the previous one ended.
- d (indices) asks the engine to record start and end offsets for each group; it does not change what matches.
In Match Details, a group shown as undefined did not participate in that match (for example the unused side of an alternation), while (empty) means it matched an empty string. Zero-length matches, such as those produced by \b or ^with the m flag, appear as a thin orange marker in the preview.
Limitations
- Only the JavaScript flavor is supported. PCRE features such as possessive quantifiers, atomic groups, recursion or inline modifiers like (?i) are rejected as syntax errors.
- A pattern that needs more than one second on your text is stopped. That protects the page, but it also means a legitimately slow pattern on a very large input will not finish here.
- The preview lists up to 1,000 matches and shows group details for the first 200, to keep the page responsive.
- Lookbehind and the d flag require a reasonably modern browser; older Safari versions report them as syntax errors.
Tips and common mistakes
- Double escaping. In a JavaScript string literal you must write "\\d+"; in this tester (and in a /\d+/ literal) you write the pattern once, with single backslashes.
- Anchor validators. \d{5} also matches inside 123456; use ^\d{5}$ to validate a whole value.
- Prefer lazy or negated classes. "[^"]*" is faster and more predictable than ".*?" for quoted strings.
- Avoid nested quantifiers. Try the Backtracking demo example to see how ^(a+)+$ explodes on a string that almost matches.
- Reusing a global regex in your own code keeps state in lastIndex; reset it or create a new RegExp before each test().
Related tools: clean up the text before matching with the Text Diff checker, or format the JSON you extracted with the JSON Formatter.
Frequently Asked Questions
Which regex flavor does this tool use?
It uses your browser's JavaScript (ECMAScript) RegExp engine, the same one Node.js and Deno use. Named groups, lookbehind, Unicode property escapes (with the u flag) and the s, y and d flags all work as they do in your JavaScript code.
Why did I get "Pattern took too long"?
Your pattern probably triggers catastrophic backtracking: nested or overlapping quantifiers such as (a+)+$ force the engine to try an exponential number of paths when a match fails. The tester runs every pattern in a Web Worker and stops it after one second, so the page keeps working; rewrite the pattern so each character can be matched in only one way.
How do I reference capture groups in the replacement?
Use $1, $2… for numbered groups, $<name> for named groups, $& for the whole match and $$ for a literal dollar sign. These follow String.prototype.replace, so the preview is exactly what your JavaScript code will produce.
What is the difference between the g and y flags?
With g the engine searches for the next match anywhere after the previous one. With y (sticky) each match must start exactly where the previous one ended, so matching stops at the first gap; it is handy for writing tokenizers.
Will my pattern behave the same in Python, Java or PCRE?
Basic syntax is shared, but details differ: Python uses (?P<name>…) for named groups, possessive quantifiers and atomic groups are not available in JavaScript, and \d or \w may be Unicode-aware in other engines. Always re-test in the target language for edge cases.
Is my text sent to a server?
No. The pattern and test string are processed entirely in your browser, inside a Web Worker created by the page. Nothing is uploaded or stored.
Related tools
- UUID GeneratorGenerate RFC 4122 compliant UUIDs (v1, v4, v5) in bulk. Export as JSON, CSV, or plain text.
- Lorem Ipsum GeneratorGenerate Lorem Ipsum placeholder text in paragraphs, sentences, or words with optional HTML output.
- QR Code GeneratorGenerate customizable QR codes for URLs, text, emails, WiFi, vCards, and phone numbers.
- QR Code ScannerScan QR codes with your camera or from an image file directly in the browser. Copy the result, open safe links and see the decoded content type.
- SQL Formatter & BeautifierFormat and beautify SQL queries with proper indentation, keyword capitalization, and syntax highlighting.
- JWT GeneratorGenerate and sign JSON Web Tokens (JWT) with custom header, payload, and secret. Supports HS256, HS384, HS512, RS256 algorithms.
Found a bug or a wrong result? Report it.