Test regular expressions with live matching, highlights, and capture groups.
The tool passes your pattern to your browser's own JavaScript regex engine, new RegExp(pattern, flags). So a pattern behaves here the way it behaves in JavaScript code in the same browser. Other languages can give different results. See the last section below.
/ inside it. Copy Regex adds the backslash for you.(?<year>\d{4}) works, but its name is not shown. A group that took no part in the match shows undefined.g flag off, only the first match is shown. With it on, the list stops at 10,000 matches.A worked example. The pattern (\d{4})-(\d{2})-(\d{2}) on the text Due 2025-04-06 and 2026-01-15. gives 2 matches. The first is 2025-04-06 at index 4, with groups 2025, 04 and 06. The second is 2026-01-15 at index 19.
Every example below was run with the g flag, the default here.
| Token | Meaning | Example → matches |
|---|---|---|
. | Any character except a line break | c.t on cat cut c-t ct → cat, cut, c-t |
\d \w \s | A digit; a letter, digit or _; a space, tab or line break | \w+ on hi_there, 42! → hi_there, 42 |
[aeiou] | One of these characters | on regex → e, e |
[^0-9] | Any character not in the set | [^0-9]+ on ab12cd → ab, cd |
^ $ | Start and end of the text (of each line with m) | ^Hi on Hi, Hi → the first Hi only |
\b | Word boundary | \bcat\b on cat concat → cat (not the one in concat) |
* + ? | 0 or more; 1 or more; 0 or 1 | colou?r on color colour → both |
{2,3} | Between 2 and 3 times | \d{2,3} on 1 12 1234 → 12, 123 |
*? +? | Lazy: as few as possible | see Common mistakes below |
( ) | Capture group | (ha)+ on hahaha! → hahaha, Group 1 = ha |
(?: ) | Group without capturing | (?:ab)+ on ababx → abab |
| | Either side | cat|dog on cat and dog → cat, dog |
(?= ) (?! ) | Followed by; not followed by | \d(?! USD) on 5 USD 7 EUR → 7 |
(?<= ) (?<! ) | Preceded by; not preceded by | (?<=\$)\d+ on cost $42 and 7 → 42 |
\ | Makes a special character literal | \$\d+ on cost $42 → $42 |
The tool offers g, i, m and s. g is on by default and finds every match. i ignores upper and lower case, so colou?r also matches COLOUR. m changes ^ and $: on the three lines one, two, three, the pattern ^\w+ matches only one, but with m it matches all three. s lets . match a line break too.
The flags u, y, d and v are not offered. Without u, two things surprise people:
\p{L} does not mean any letter. On café p{L}, the pattern \p{L}+ matches the literal text p{L}.. on 😀 gives 2 matches, each half of the emoji.<.+> on <b>bold</b> matches the whole string, because .+ takes as much as it can. The lazy version <.+?> matches <b> and </b> separately.example.com, the dot matches any character, so exampleXcom matches too. Write example\.com.^ to mean start of line. Without the m flag it means start of the whole text.+1 (555) 010-019, cutting off the last digit, and also matched the date 2024-01-05. IP Address matched 999.300.1.1. Date matched 2024-13-45. URL kept a comma or full stop at the end of a sentence./ inside the pattern. So a/b is copied as /a\/b/g, which works as it is in JavaScript code. A quoted string is different. In new RegExp("\\d+"), the slashes and flags are not part of the string, and every backslash must be doubled.Some patterns take a very long time on text that almost matches. This is called catastrophic backtracking. The classic example is ^(a+)+$ on a line of a's followed by one b. The engine tries every way to split the a's between the inner and outer +, and each extra a roughly doubles the work. We timed it in Node.js, which uses the same V8 engine as Chrome. With 26 a's it took about 0.3 seconds, with 28 about 1 second, and with 29 about 2 seconds. A few more a's take minutes.
So this tool does not run the match on the page itself. It runs it in a Web Worker, a separate background thread, and gives it 1.5 seconds. If the match is not finished by then, the tool stops the worker and shows Stopped after 1.5 seconds: this pattern is too slow on this text. The page and your text stay as they are, and the next change you make starts a fresh run. If a run takes more than a moment, the status line shows Matching… while you wait.
A stopped pattern is a warning for your own code too. In a real program there is usually no time limit, so the same pattern can hang a server or an app. To avoid the problem, do not nest quantifiers, as in (a+)+ or (\w*)*. ^a+$ matches the same text and stays fast.
Most basic syntax is the same everywhere. These are the differences you are most likely to meet when a pattern comes from Python, PHP or Java:
(?P<name>…) is an error here: Invalid group. JavaScript writes (?<name>…).a++ and atomic groups (?>…) are errors here.(?i)abc, is an error. Use the checkbox.\A and \Z do not mean start and end of text. \A just matches the letter A. Use ^ and $.So if a pattern works here, test it once more in the language where you will use it.
It uses the JavaScript regex engine built into your browser. You can turn on four flags: g for all matches, i to ignore case, m so that ^ and $ work per line, and s so that the dot also matches a line break. The flags u, y, d and v are not offered.
Unicode property escapes such as \p{L} only work with the u flag, and this tool does not offer it. Without u, the pattern \p{L} matches the literal text p{L}. Test such patterns in your own code with the u flag, or use a character range such as [A-Za-z] here.
No. Matching runs in a background thread with a time limit of 1.5 seconds. A pattern with nested quantifiers, such as ^(a+)+$, can take minutes on text that almost matches. The tool stops it and shows a message instead. Rewrite the pattern without nesting, for example ^a+$.
Copy Regex puts slashes around your pattern, adds the flags and escapes each slash inside the pattern. So a/b is copied as /a\/b/g, which you can paste into JavaScript code as it is. If you build the regex from a quoted string instead, leave out the outer slashes and flags, and double every backslash.
Each language has its own regex rules. Python named groups written as (?P<name>...), possessive quantifiers such as a++, atomic groups and inline flags such as (?i) are errors in JavaScript. Other patterns may run but match differently. Always test the pattern in the language where you will use it.
No. The pattern and the test text are matched by your browser. Nothing is uploaded, and nothing is saved when you close the page.