Test a JavaScript regex: every match marked, each group in a table, Replace with $1, and the pattern explained
Type a JavaScript regular expression and paste your text: every match is marked as you type, each group gets its own column, and every part of the pattern is explained in plain English. Replace shows the new text with $1 and $<name>.
How to use it
Type a pattern, or pick a common one, and open Flags for the ones it needs (g finds every match). Paste the text to test, or open a file of up to 10 MB. Read the matches and their groups (click one to find it in the text), switch to Replace, Explanation, Tests, Code or Steps, and copy the matches as JSON, CSV or text.
Examples
Dates, with named groups
/(?<year>\d{4})-(?<month>\d{2})/g
Shipped 2026-10-15, paid 2026-09-30.[
{
"match": "2026-10",
"year": "2026",
"month": "10"
},
{
"match": "2026-09",
"year": "2026",
"month": "09"
}
]Copy gives each match with its groups by name, as JSON, JSON Lines, CSV or text.
Prices after a dollar sign (lookbehind)
/(?<=\$)\d+(?:\.\d{2})?/g
Total $42.50, tax $3, code A12.[ "42.50", "3" ]
(?<=\$) checks for the $ without making it part of the match; A12 has no $ before it.
Key = value lines, with the m flag
/^(\w+)\s*=\s*(.*)$/gm host = example.com port=8080 # a comment
[
{
"match": "host = example.com",
"group 1": "host",
"group 2": "example.com"
},
{
"match": "port=8080",
"group 1": "port",
"group 2": "8080"
}
]With m, ^ and $ match at every line; without it, only at the start and end of the text.
Replace: a date as day/month/year
/(\d{4})-(\d{2})-(\d{2})/g
Replace with: $3/$2/$1
Renewal due 2026-11-01, review 2027-01-15.Renewal due 01/11/2026, review 15/01/2027.
A group left open
/(?<year>\d{4}/g
2026-10-15Not a valid pattern. Character 1: Unterminated group: a "(" without its ")"The part that is wrong is marked in the pattern, and the explanation reads up to it.
JavaScript, PCRE2, Python, Go, Java, .NET and Rust
Sources: MDN: Regular expressions, PCRE2 pattern syntax, Python re, Go regexp/syntax, Java Pattern, .NET regular expressions, Rust regex syntax
The flags
| Flag | Name | What it does |
|---|---|---|
g | global | Finds every match, not just the first |
i | ignore case | Upper and lower case match each other (a matches A) |
m | multiline | ^ and $ match at the start and end of every line |
s | dotAll | The dot matches line breaks too |
u | unicode | Reads the pattern as Unicode: \u{…}, \p{…}, and emoji as one character |
v | unicodeSets | Unicode, plus set operations in classes ([\p{L}--[a-z]]); not with u |
y | sticky | Matches only exactly at lastIndex, not further on |
d | hasIndices | Reports where each group matched (this tester shows that without it) |
Sources: MDN: RegExp flags
Cheat sheet
| Pattern | Matches |
|---|---|
\d \w \s | A digit; a word character (A–Z, a–z, 0–9, _); whitespace |
\D \W \S | Anything but a digit, a word character, whitespace |
. | Any character except a line break (with s, line breaks too) |
[abc] [^abc] [a-z] | One of a, b, c; anything but them; a range |
^ $ | The start and end of the text (with m, of each line) |
\b | A word boundary: between a word character and something else |
* + ? | Zero or more; one or more; zero or one, as many as possible |
{3} {2,5} {2,} | Exactly 3; 2 to 5; 2 or more |
*? +? ?? | The same, as few as possible (lazy) |
(…) (?<name>…) | A group, captured by number; by name |
(?:…) | A group that is not captured |
\1 \k<name> | The same text as group 1 matched; as the named group |
a|b | a or b |
(?=…) (?!…) | Followed by, not followed by (not part of the match) |
(?<=…) (?<!…) | Preceded by, not preceded by |
match, matchAll, exec, test and replace
| Call | Gives |
|---|---|
text.match(/…/) | The first match with its groups and index, or null |
text.match(/…/g) | Every matched string, without groups, or null |
text.matchAll(/…/g) | Every match with its groups; a TypeError without g |
re.exec(text) | One match with its groups; with g or y it starts at re.lastIndex and moves it on |
re.test(text) | true or false; with g or y it also moves lastIndex on |
text.replace(/…/, x) | The first match replaced; with g, every match |
text.replaceAll(/…/g, x) | Every match replaced; a TypeError without g |
Sources: MDN: String.prototype.matchAll(), MDN: RegExp.prototype.exec()
Replacement patterns
| Write | For |
|---|---|
$1 … $99 | The text of that numbered group |
$<name> | The text of the named group |
$& | The whole match |
$` | The text before the match |
$' | The text after the match |
$$ | A $ sign |
When a pattern takes too long
/(a+)+$/.test("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!") // stopped here; slow in your codeQuestions
- Which regex flavor does it test?
JavaScript by default, with your browser’s own engine. The Flavor menu also reads patterns by the rules of PCRE2 (PHP), Python 3.11, Go, Java 21, .NET and Rust: their anchors, dot, \d, \w and \b, named groups, inline flags, possessive repeats and atomic groups, and their replacement syntax ($1, \1, \g<name>, ${name}). - Can I save a pattern to use again?
Yes: My patterns saves the pattern in the boxes, with its flags, flavor and replacement, under a name you choose (up to 50). They are kept in this browser, not the text; pick one to fill the boxes again, or delete it there. Delete all data in Settings clears them too. - Can I see how the engine finds a match, step by step?
Yes: Steps walks the start of your text (2,000 characters) the way JavaScript’s engine does, each part of the pattern tried at its place, what it matched, and each step back when a way fails, up to the first match. A pattern that backtracks too much stops at 20,000 steps, which is how catastrophic backtracking shows. - Can it write the regex as code for my language?
Yes: Code gives the pattern and the code that finds every match (or the first) and makes the replacement, in JavaScript, Python, PHP, Go, Java, C#, Rust or Ruby. The pattern is rewritten so it matches the same text there: JavaScript’s ASCII \d, \w and \b are kept, the dot and ^ $ stop where JavaScript stops, and a Unicode property the engine lacks is written out as ranges. A note says what still differs (.NET reads emoji as two halves), and what an engine can’t do, such as a backreference in Go or Rust, is named instead of written. - Why does it find only the first match?
Without the g flag a regex stops at its first match. Open Flags and turn on g to find them all; the page says so when g is off. - Why does test() return true, then false, on the same text?
With the g or y flag, test() and exec() start at the regex’s lastIndex and move it past each match. The second call starts after the first match, finds nothing more and sets lastIndex back to 0. Use a regex without g for test(), or set re.lastIndex = 0 before each call. - Does JavaScript support lookbehind?
Yes: (?<=…) and (?<!…) are part of JavaScript since ES2018 and work in current Chrome, Edge, Firefox and Safari (16.4 and later). In JavaScript they can be any length, which many other engines don’t allow. - How do I match across lines?
The dot doesn’t match line breaks by default. Turn on the s flag so it does, or use [\s\S] for any character. To make ^ and $ match at each line instead of the whole text, turn on m. - Greedy or lazy: what is the difference?
* and + take as much as they can, then give back only what the rest of the pattern needs: ".*" on "a" and "b" matches the whole "a" and "b". Add ? to take as little as possible: ".*?" matches "a" and "b" separately. - Which characters need a backslash?
These have a meaning in a pattern: \ ^ $ . | ? * + ( ) [ ] { }. Put a backslash before one to match it as itself (\. matches a dot). In /…/ also escape /; in a string passed to new RegExp, each backslash is written twice ("\\d"). - Can a regex check an email address?
Only roughly. The common pattern finds things that look like an address, which is what most forms need; whether the address works is only known by sending mail to it. Browsers check <input type="email"> with a similar simple pattern. - How much text can it test?
Up to 10 MB, pasted or from a file. The first 10,000 matches are found and the first 500 listed in the table; Copy has every match found, as JSON, JSON Lines, CSV or text. A pattern that runs over 5 seconds is stopped. - Is my text uploaded?
No. Everything runs in your browser, so your text stays on your device. Nothing you paste is uploaded unless you share a result, which is locked with your password first. Logs can hold API keys and tokens, and the page warns you if it spots one.