Regex tester: test regular expressions with live match highlighting
A regex tester lets you write a regular expression and see immediately which parts of a sample text it matches, including capture groups and named groups. This tester uses your browser’s JavaScript engine, so behaviour matches Node and browser code exactly; it supports the g, i, m, s, u and y flags, shows every match with its groups, previews a replacement string, and includes a quick reference of syntax.
Your files never leave your device. Processing happens in your browser.How that works.
How it works
- Type a pattern and pick flags.
- Paste sample text; matches highlight as you type.
- Inspect groups in the match list, or enter a replacement to preview the result.
Runs as JavaScript inside this tab. Turn off your connection after the page loads and it still works.
Regular expression cheat sheet (JavaScript)
Characters
| Syntax | Matches |
|---|---|
. |
Any character except newline (s flag: including newline) |
\d \w \s |
Digit [0-9]; word character [A-Za-z0-9_]; whitespace |
\D \W \S |
The opposites |
\b \B |
Word boundary; not a word boundary |
\n \t \r \0 |
Newline, tab, carriage return, NUL |
\xHH \uHHHH \u{H…} |
Code unit / code point (last form needs u) |
\p{L} \p{Script=Greek} \p{Emoji} |
Unicode property (needs u or v) |
\. \* \? |
Literal special character |
Character classes
| Syntax | Matches |
|---|---|
[abc] |
a, b or c |
[a-z] [0-9A-F] |
Ranges |
[^abc] |
Anything except a, b, c |
[\w.-] |
Word char, dot or hyphen |
[\p{L}\p{N}] |
Any letter or number (with u) |
Quantifiers
| Syntax | Meaning |
|---|---|
* + ? |
0 or more; 1 or more; 0 or 1 |
{3} {2,5} {2,} |
Exactly 3; 2 to 5; at least 2 |
*? +? ?? {2,5}? |
Lazy: match as little as possible |
Quantifiers are greedy by default: <.+> on <a><b> matches the whole string; <.+?> matches <a>.
Anchors and lookaround
| Syntax | Meaning |
|---|---|
^ $ |
Start / end of input; with m, of each line |
(?=x) (?!x) |
Followed by x / not followed by x (lookahead) |
(?<=x) (?<!x) |
Preceded by x / not preceded by x (lookbehind) |
Groups and references
| Syntax | Meaning |
|---|---|
(x) |
Capture group; $1 in replacement, \1 in pattern |
(?<name>x) |
Named group; $<name> / \k<name> |
(?:x) |
Group without capturing |
x|y |
x or y |
Flags
| Flag | Effect |
|---|---|
g |
Global: find every match |
i |
Case-insensitive |
m |
^ $ match at line breaks |
s |
. matches newlines |
u |
Unicode mode: \p{…}, correct astral-plane handling |
y |
Sticky: match only at lastIndex |
v |
Unicode sets: [\p{L}--[a-z]], string properties |
d |
Generate match indices for groups |
Replacement strings
$1, $<name>, $& (whole match), $` (before), $' (after), $$ (literal $). In code, pass a function to replace for anything more complex.
Performance warning
Patterns with nested quantifiers such as (a+)+$ or (\w+\s?)*$ can take exponential time on non-matching input (catastrophic backtracking) and will freeze the tab. Prefer possessive-style structure: anchor the pattern, make alternatives mutually exclusive, and avoid (x*)*.
JavaScript vs other flavours
| Feature | JavaScript | PCRE / Python | .NET |
|---|---|---|---|
| Named groups | (?<n>…) |
(?P<n>…) (Python), (?<n>…) (PCRE) |
(?<n>…) |
| Lookbehind | Yes (variable length) | Fixed length in PCRE/Python | Yes |
Possessive a++, atomic (?>…) |
No | Yes | Yes |
\A \Z |
No (use ^ $ without m) |
Yes | Yes |
Inline flags (?i) |
No ((?i:…) from ES2025) |
Yes | Yes |
Recursion (?R) |
No | PCRE yes | No |
Worked examples
Extract dates with named groups
Pattern (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}), flags g, text Released 2026-09-10, patched 2026-10-01.
Two matches. The match list shows $<year>="2026" $<month>="09" $<day>="10" for the first. Replacement $<day>/$<month>/$<year> rewrites the text to Released 10/09/2026, patched 01/10/2026.
Find duplicated words
Pattern \b(\w+)\s+\1\b, flags gi, text This is is a test of the the tester. Matches is is and the the; the back-reference \1 requires the second word to equal the first capture.
Why does ^ not match every line?
Pattern ^\w+, text with three lines: without m only the first line matches. Tick m and each line start is an anchor.
Lazy vs greedy
Text <b>bold</b> and <i>italic</i>. Pattern <.+> matches the whole string (greedy); <.+?> matches <b>, </b>, <i>, </i> (lazy).
Escaping user input
To search for a literal 1.5*2?, escape it as 1\.5\*2\?. The escaped form of any string can be built with s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').
Frequently asked questions
Which regex flavour does this use?
JavaScript (ECMAScript), as implemented by your browser. Lookbehind, named groups and Unicode property escapes are supported in all modern browsers.
What does the g flag do?
Global: find all matches instead of stopping at the first. Without it, only the first match is reported.
Why does my pattern match nothing?
Common causes: forgetting to escape a dot or bracket, needing the m flag for ^ and $ to match at line boundaries, or needing the s flag for . to match newlines.
How do I use a capture group in the replacement?
Use $1, $2 for numbered groups or $<name> for named groups. $& inserts the whole match.
Regex tester · last updated · changelog · part of Canned Tuna