How to use the Regex Tester
- Type a Pattern without surrounding slashes, for example
\d{4}-\d{2}-\d{2}. - Set Flags, such as
gfor all matches orgifor all matches ignoring case. Letters that aren’t valid JavaScript flags are ignored, and a warning names them, for exampleIgnored unknown flag: x (valid: d g i m s u v y). - Paste the Test text. Matches update as you type.
- Switch Mode to Replace and fill in Replace with to preview a find-and-replace.
Each match shows its line, its index range in the text and every capture group. Named groups are labeled with their name next to the number, so $1 and user appear on one line:
Match 1 · line 2 · index 12–35
"linh.nguyen@example.com"
$1 user "linh.nguyen"
$2 domain "example.com"
A group that didn’t take part in the match is shown as (not matched). The list stops at 1,000 matches, with a warning showing the total.
Flags
| Flag | Effect |
|---|---|
g |
Find all matches, not just the first |
i |
Ignore case |
m |
^ and $ match at every line break |
s |
. also matches line breaks |
u |
Unicode mode: full code points, \p{L} property escapes |
v |
Unicode sets mode (newer superset of u) |
y |
Sticky: match only at the current position |
d |
Record match indices |
Replacement tokens
| Token | Inserts |
|---|---|
$1, $2 … |
Numbered capture group |
$<name> |
Named group, from (?<name>…) |
$& |
The whole match |
$$ |
A literal $ |
With pattern (\d+)-(\d+)-(\d+) and replacement $3/$2/$1 [$&] $$, the text 2026-09-27 becomes 27/09/2026 [2026-09-27] $. Without the g flag, only the first match is replaced.
Common patterns
| Purpose | Pattern |
|---|---|
| ISO date | \d{4}-\d{2}-\d{2} |
| Integer or decimal | -?\d+(\.\d+)? |
| Hex color | #(?:[0-9a-fA-F]{3}){1,2}\b |
| UUID | [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} |
| Leading/trailing spaces | ^\s+|\s+$ (with gm) |
| Word in any language | \p{L}+ (with u) |
Simple email patterns like the default sample are fine for extracting addresses from text. Don’t rely on a regex alone to validate them.
Avoiding slow patterns
Nested quantifiers such as (a+)+, or alternations that overlap like (\w|\d)+, can backtrack exponentially on input that almost matches. Prefer specific character classes, anchor with ^ and $ where you can, and test with a long non-matching string before shipping a pattern.
If a pattern does run away here, the tester stops it after 5 seconds and says so instead of freezing the tab. Treat that message as an early warning: the same pattern would stall a server request or a log pipeline on similar input.
In code
const re = /(?<user>[\w.+-]+)@(?<domain>[\w-]+\.[\w.]+)/g;
for (const m of text.matchAll(re)) console.log(m.index, m.groups.user, m.groups.domain);
text.replace(re, '$<user> at $<domain>');
Related workflows
- Preview a bulk rename in Replace mode, then paste the old and new text into Text Diff to review every changed line before applying it in your editor.
- To change identifier styles rather than match them, use the Case Converter.
- For structured data, a regex over raw JSON is fragile. Query it with the JSONPath Tester instead, which matches by key and value rather than by text layout.
Frequently asked questions
Which regex flavor is this?
JavaScript (ECMAScript), exactly as your browser runs it. Patterns behave the same as in Node.js, Deno and browser code. Syntax from PCRE, Python or Go that JavaScript doesn't support, such as possessive quantifiers or inline (?i) flags, reports an Invalid pattern error.
Why do I see only one match?
Without the g flag, a regular expression stops after the first match. The tool shows that match and a warning with the total count. Add g to the Flags box to list every match.
How do I use capture groups in the replacement?
Use $1, $2 for numbered groups, $<name> for named groups, $& for the whole match and $$ for a literal dollar sign.
Can a pattern freeze the page?
Yes, if it causes catastrophic backtracking, for example nested quantifiers like (a+)+ against a long non-matching string. The pattern runs in a background worker, so the page keeps responding, and a run that takes longer than 5 seconds is stopped with a message. Simplify the pattern and try again.
Is my text uploaded?
No. Matching and replacing run in your browser. Nothing is uploaded.
Last updated