Regex Tester
Free online regex tester: live match highlighting, capture and named groups, g/i/m/s/u/y flags, replace preview and a cheat sheet. Runs in your browser.
| # | Index | Match | Groups |
|---|
Use $1, $<name>, $& (whole match) or $$ for a literal dollar sign.
Regex cheat sheet
.Any character except line breaks\d \w \sDigit, word character, whitespace\D \W \SNot digit, not word, not whitespace[abc] [^abc]One of / none of a, b, c[a-z0-9]Character range^ $Start / end of input (or line with m)\bWord boundary* + ?0+, 1+, 0 or 1 times{3} {2,5}Exactly 3, between 2 and 5*? +?Lazy (as few as possible)(abc)Capture group(?<name>abc)Named capture group(?:abc)Non-capturing groupa|ba or b(?=x) (?!x)Followed / not followed by x(?<=x) (?<!x)Preceded / not preceded by x\1 \k<name>Back-reference to a group$1 $<name> $&Replacement: group, named group, whole matchTest regular expressions as you type
This regex tester runs your pattern against sample text and updates the result a moment after you stop typing. Every match is highlighted in the text, listed with its position and capture groups, and you can preview a search-and-replace before using the expression in your code, editor or spreadsheet. It uses the JavaScript regular expression engine built into your browser, so the behaviour is exactly what you will get in JavaScript, TypeScript or Node.js.
How to use it
- Write the pattern between the slashes, without the delimiters. For example
\b\w+@\w+\.\w+\bfinds simple email addresses. - Choose flags.
gis on by default so every match is shown; addito ignore case ormto make^and$work per line. - Paste your test text. Matches are highlighted and listed with their start index and every numbered and named group.
- Try a replacement. Type a replacement string to see the full result, using
$1or$<name>to reuse captured text.
Example: reformat dates with named groups
Safe testing and invalid patterns
If the pattern is not valid, for example an unclosed group or a stray quantifier, the tester shows the browser's error message instead of failing silently. To keep the page responsive, the expression runs in a background worker only when the input changes, results stop after 1,000 matches, and a pattern that takes longer than about one second is stopped. That protects you from catastrophic backtracking, which happens with nested quantifiers such as (a+)+$ on long inputs. If you hit the limit, make the pattern more specific: replace .* with a negated class like [^,]*, avoid repeating groups that can match the same text, and anchor the pattern where possible.
Common patterns
- Whole word:
\bword\b - Numbers with decimals:
-?\d+(?:\.\d+)? - Leading or trailing spaces:
^\s+|\s+$with thegandmflags - Hex colours:
#(?:[0-9a-fA-F]{3}){1,2}\b - Duplicate words:
\b(\w+)\s+\1\bwith theiflag
Frequently Asked Questions
Which regex flavor does this tester use?
It uses your browser's JavaScript (ECMAScript) regular expression engine, the same one used by JavaScript, TypeScript and Node.js. Most syntax is shared with PCRE, Python and Java, but some features such as possessive quantifiers or inline modifiers differ.
What do the g, i, m, s, u and y flags do?
g finds all matches instead of the first, i ignores case, m makes ^ and $ match at line breaks, s lets the dot match new lines, u enables full Unicode mode (needed for \p{...} classes), and y (sticky) only matches at the current position.
How do I use named capture groups?
Write (?<name>...) to capture a group with a name, refer to it inside the pattern with \k<name> and in the replacement with $<name>. The match list shows every named group next to the numbered ones.
Why does my pattern freeze or time out?
Nested quantifiers such as (a+)+ or (.*)* can cause catastrophic backtracking, where the engine tries an exponential number of paths. The tester runs your pattern in a background worker and stops it after about one second, so rewrite the pattern with more specific character classes or fewer nested repeats.
Is my test data uploaded anywhere?
No. The pattern, text and replacement stay in your browser and are processed locally with JavaScript.