Regex Tester
Test JavaScript regular expressions with live highlighting, capture groups and replace
Type the pattern without the surrounding slashes. Pasting a literal such as /ab+c/gi splits it into pattern and flags.
Matches are highlighted below as you type. The test text stays on this page and is never included in shared links.
Use $1 to $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.
Matches
Match details
| # | Index | Match | Groups |
|---|
Replace preview
Quick reference
. | Any character except a line break (any at all with s) |
|---|---|
\d \D | Digit 0-9 / not a digit |
\w \W | Word character A-Z a-z 0-9 _ / not one |
\s \S | Whitespace / not whitespace |
[abc] | Any one of a, b or c |
[^abc] | Any character except a, b or c |
[a-z] | Any character from a to z |
\p{L} | Any letter in any script (needs u or v) |
\t \n \r | Tab, line feed, carriage return |
\. \* \\ | A literal dot, asterisk, backslash |
^ $ | Start / end of the text (of each line with m) |
|---|---|
\b \B | Word boundary / not a word boundary |
* + ? | 0 or more, 1 or more, 0 or 1 |
{3} | Exactly 3 |
{2,5} | Between 2 and 5 |
{2,} | 2 or more |
*? +? ?? | Lazy: as few as possible |
(abc) | Capture group, numbered from 1 |
|---|---|
(?<name>abc) | Named capture group |
(?:abc) | Group without capturing |
a|b | a or b |
\1 \k<name> | Back-reference to a group |
(?=abc) | Followed by abc |
(?!abc) | Not followed by abc |
(?<=abc) | Preceded by abc |
(?<!abc) | Not preceded by abc |
About regular expressions
A regular expression (regex) is a compact pattern for finding text: every UK postcode in a document, every IP address in a log file, or every date written as 2026-11-09. They are built into almost every programming language, text editor, database and command-line tool. This tester uses your browser's own JavaScript engine, so a pattern that works here behaves the same in JavaScript and TypeScript code, and in Node.js and Deno. HTML pattern attributes use the same engine, but always with the v flag and only when the whole value matches. Other flavours such as PCRE (PHP, grep -P), Python and .NET are very similar, but differ in details such as lookbehind support, named-group syntax and flags.
How to use the tester
- Type your pattern into the Regular expression box, without slashes. Errors are explained in plain English as you type.
- Tick the flags you need.
gfinds every match rather than the first,iignores case,mmakes^and$work per line,slets a dot match line breaks,uenables full Unicode,yonly matches where the previous match ended, andv(where your browser supports it) adds set operations inside classes. - Paste the text to test against. Matches are highlighted in alternating colours, and the Match details table lists each match's position (a zero-based character index) and every capture group, by number and by name. A group that did not take part in a match is shown as "no match", which is different from matching an empty string.
- To try a substitution, type a replacement pattern. The Replace preview shows the result of
text.replace(regex, replacement): without thegflag only the first match is replaced. - Copy link shares the pattern and flags (as
?re=and&flags=). Your test text is deliberately left out, so log extracts and personal data are not leaked through a link.
Worked example
Press the ISO date example. The pattern (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) with the g flag finds both dates in the sample text, and each row of the details table shows year, month and day as named groups (also available as groups 1, 2 and 3). The replacement $<day>/$<month>/$<year> rewrites them in British DD/MM/YYYY order, so 2026-03-29 becomes 29/03/2026. Untick g and only the first date is matched and replaced.
Catastrophic backtracking
JavaScript's regex engine is a backtracking engine. When a pattern contains nested or overlapping quantifiers, such as (a+)+$ or (\w+\s?)*$, and the text almost matches, the engine may try an exponential number of ways to split the text before giving up. Each extra character doubles the work: forty characters can take minutes or hours, and fewer than a hundred can take longer than the age of the universe. On a server this is a denial-of-service hole known as ReDoS. This tester runs every match in a separate background worker, and if it has not finished within two seconds the worker is stopped and you are told why, so the page never freezes. Try the Catastrophic backtracking example to see it. The cure is to make the alternatives unambiguous: ^a+$ does the same job as ^(a+)+$ instantly.
Limitations
Only JavaScript syntax is supported; flavour-specific features such as possessive quantifiers, atomic groups, inline modifiers like (?i) and recursion are reported as errors. The v flag needs a recent browser. To keep the page responsive, at most 5,000 matches are found and 1,000 are listed in the table. Character indexes count UTF-16 code units, as JavaScript does, so most emoji count as two or more.
Privacy
Matching runs entirely in your browser, in a worker created on the page itself. Your pattern and test text are never sent to a server or stored. Only the pattern and flags go into the address bar, and only when you use the page; the test text never does.
Common questions
What does \d mean in regex?
In a regular expression, \d matches any single digit from 0 to 9. Add a quantifier to match more than one: \d+ matches one or more digits and \d{4} matches exactly four. The capital form, \D, matches any character that is not a digit. In JavaScript \d covers only the digits 0 to 9; some other flavours also accept digits from other scripts.
What is the difference between .* and .*? in regex?
In a regular expression, .* is greedy and .*? is lazy. The greedy form matches as much text as it can while still letting the rest of the pattern succeed; the lazy form matches as little as it can. Against <b>one</b><b>two</b>, the pattern <b>.*</b> matches the whole string, while <b>.*?</b> stops at the first closing tag.
What do ^ and $ mean in regex?
In a regular expression, ^ matches the start of the text and $ matches the end, so ^\d+$ only matches text made up entirely of digits. Neither consumes a character; they are positions. With the m (multiline) flag they match at the start and end of every line instead. Inside square brackets ^ means something else: [^0-9] matches any character that is not a digit.
How do I match a full stop or other special character in regex?
To match a special character literally in a regular expression, put a backslash in front of it: \. matches a full stop and \? a question mark. The characters that need this are . * + ? ^ $ { } ( ) [ ] | \. An unescaped dot matches almost any character, which is why example.com also matches "exampleXcom".