Regex Tester – Test JavaScript Regular Expressions
Type a pattern and see every match highlighted live. This regex tester lists each match with its position and capture groups, including named groups, and previews replacements with $1 and $<name>.
Use $1 for group 1, $<name> for a named group, $& for the whole match and $$ for a dollar sign.
Press Ctrl+Enter (⌘+Enter on Mac) to run now.
Contact: [email protected], [email protected] Docs: https://example.com/docs?page=2 and http://test.example.org/a-b Server 192.168.1.20 replied at 14:35 on 2026-03-09 (10.0.0.256 is not an IP) Brand colors: #4F46E5, #fff and #10b98180 Request ID 3f2b8c1e-9a4d-4e6b-8f21-0c7d5e9a1b42 Call +14155552671 for the the details 🎉 <p class="note">Hello <b>world</b></p>Linecolumn
Test Regular Expressions as You Type
A regular expression that works on one example can still miss half your data or match far too much. This regex tester runs your pattern against real text on every keystroke, highlights each match and lists its exact position and capture groups, so you can see what the expression really does before it goes into your code, a log search or a form validation rule.
It uses the JavaScript regex engine built into your browser, the same one that runs your front-end code and Node.js, with all flags including d and v where supported. Matching runs in a background worker with a time limit, so a pattern with catastrophic backtracking is stopped instead of freezing the page. Nothing you type is sent to a server.
How to test a regex
- Enter the pattern between the slashes, or pick one of the common patterns such as email, URL, IPv4 or ISO date.
- Tick the flags you need. Most searches need
gto find every match instead of only the first one. - Paste your test string. Matches are highlighted as you type; zero-length matches show as a thin red marker.
- Check the match details. Each row shows the start and end index and every capture group. Click a row to select that match in the test string.
- Switch to Replace to preview a substitution such as
$<day>/$<month>/$<year>, then copy the result or the regex literal.
JavaScript regex flags
| Flag | Name | What it does |
|---|---|---|
g | global | Find all matches instead of stopping after the first. |
i | ignoreCase | a also matches A. |
m | multiline | ^ and $ match at the start and end of every line, not only of the whole text. |
s | dotAll | . also matches line breaks. |
u | unicode | Treats the pattern as code points, enables \u{1F600} and \p{…} property escapes, and makes invalid escapes errors. |
y | sticky | A match must start exactly at lastIndex (here: at the start, then directly after the previous match). |
d | hasIndices | Records the start and end of every capture group (ES2022). Hover a group cell to see its position. |
v | unicodeSets | An upgraded u mode with set operations such as [\p{L}--[a-z]] (ES2024). It cannot be combined with u. |
Regex syntax cheat sheet
| Syntax | Matches | Example |
|---|---|---|
. | Any character except a line break (any character with s) | a.c → abc, a-c |
\d \w \s | Digit, word character [A-Za-z0-9_], whitespace; upper case negates (\D) | \d{3} → 123 |
[abc] [^abc] [a-z] | One character from a set, not in a set, or in a range | [aeiou] → vowels |
* + ? {n,m} | 0 or more, 1 or more, 0 or 1, between n and m times | \d{2,4} |
*? +? ?? | Lazy versions: match as little as possible | <.+?> → one tag |
^ $ \b | Start, end, word boundary | \bcat\b |
(…) (?:…) | Capturing group, non-capturing group | (\d+)px |
(?<name>…) | Named capturing group | (?<year>\d{4}) |
\1 \k<name> | Backreference to a group | (\w)\1 → ll, ee |
a|b | Either side | cat|dog |
(?=…) (?!…) | Lookahead, negative lookahead | \d+(?=px) |
(?<=…) (?<!…) | Lookbehind, negative lookbehind | (?<=\$)\d+ |
\p{L} | Unicode property (needs u or v) | \p{Lu} → upper-case letters |
Replacement patterns
Replace mode uses String.prototype.replace, so it understands the same tokens as your code: $1–$99 for numbered groups, $<name> for named groups, $& for the whole match, $` and $' for the text before and after it, and $$ for a dollar sign.
Catastrophic backtracking
JavaScript uses a backtracking regex engine. When a pattern can match the same text in many different ways, such as ^(a+)+$ against a long run of a followed by !, the engine tries every combination before it gives up, and the work doubles with each extra character. On a server this is known as ReDoS (regular expression denial of service). Load the “Catastrophic backtracking demo” pattern to see it: the tester stops the background worker after 2 seconds and tells you why. To fix such patterns, remove nested quantifiers, make alternatives mutually exclusive and anchor the expression where you can.
Tips for writing regular expressions
- Escape special characters
. * + ? ^ $ { } ( ) | [ ] \ /with a backslash when you mean them literally. - Use named groups for anything longer than two groups;
match.groups.yearis easier to read thanmatch[3]. - Hidden characters such as zero-width spaces can stop a match that looks right. Clean the text with the Invisible Character Cleaner.
- Parsing URLs? The URL Parser splits them correctly, including encoded characters, without a fragile pattern.
Frequently Asked Questions
Common questions about testing regular expressions.
It uses JavaScript (ECMAScript) regular expressions, run by your browser’s own engine. Results match what RegExp, String.prototype.match and replace do in browsers and Node.js. Other flavors such as PCRE or Python differ in details like possessive quantifiers and inline modifiers.
The g (global) flag is off. Without it, JavaScript stops after the first match. Tick g to find all matches.
Write (?<name>…), for example (?<year>\d{4}). The group appears as a column labelled with its number and name, and in Replace mode you insert it with $<year>.
A match that consumes no characters, produced by patterns like ^, \b or a*. The tester shows it as a thin red marker and moves one character forward (one code point in u or v mode) so the search cannot loop forever.
Matching took longer than 2 seconds, which almost always means catastrophic backtracking caused by nested quantifiers or overlapping alternatives. The background worker is stopped so the page stays responsive.
The d flag (hasIndices) makes the engine record the start and end index of each capture group. With it on, hover a group cell in the match table to see its exact position.
The pattern breaks a syntax rule, for example an unclosed group, a quantifier with nothing before it, or an escape that is invalid in u mode. The browser’s error message is shown below the inputs.
No. The pattern and the test string stay in your browser; matching runs in a local Web Worker.