Developer tool
Regex Tester
Test JavaScript regular expressions live: highlighted matches, capture groups, named groups, replace preview, flags and a built-in cheat sheet.
Free, no sign-up. Runs in your browser; nothing is uploaded.
Pattern
Test string
Highlighted matches
Match details
- #1
"sales@example.com"index 8-25, line 1, col 9 - #2
"support+uk@mail.example.co.uk"index 29-58, line 1, col 30
Replace preview
Turn this on to preview a replacement using $1, $& or $<name>.
Notes on safety
Everything runs in your browser. Results stop at 5,000 matches. A pattern with nested quantifiers such as (a+)+$ can still take very long on certain inputs (catastrophic backtracking); if the page stops responding, reload it and simplify the pattern.
Regex cheat sheet
Anchors
^ | Start of input (or line with m) |
$ | End of input (or line with m) |
\b | Word boundary |
\B | Not a word boundary |
Character classes
. | Any character except newline (any with s) |
\d \D | Digit / non-digit |
\w \W | Word character / non-word |
\s \S | Whitespace / non-whitespace |
[abc] | Any of a, b, c |
[^abc] | None of a, b, c |
[a-z] | Range |
\p{L} | Unicode letter (needs u flag) |
Quantifiers
* | 0 or more |
+ | 1 or more |
? | 0 or 1 |
{n} | Exactly n |
{n,} | n or more |
{n,m} | Between n and m |
*? +? ?? | Lazy (as few as possible) |
Groups
(abc) | Capture group, numbered from 1 |
(?<name>abc) | Named capture group |
(?:abc) | Non-capturing group |
a|b | Alternation: a or b |
\1 \k<name> | Back-reference |
Lookaround
(?=abc) | Positive lookahead |
(?!abc) | Negative lookahead |
(?<=abc) | Positive lookbehind |
(?<!abc) | Negative lookbehind |
Flags
g | Global: find all matches |
i | Ignore case |
m | Multiline anchors |
s | Dot matches newline |
u | Unicode mode |
y | Sticky: match only at lastIndex |
d | Capture group indices |
Escapes
\n \t \r | Newline, tab, carriage return |
\. \* \\ | Literal special character |
\u00e9 | Unicode code unit |
\x41 | Hex character code |
Replacement tokens
$1 $2 | Captured group |
$<name> | Named group |
$& | Whole match |
$$ | Literal dollar sign |
How to use the regex tester
Testing a pattern step by step
Type your expression into the pattern box, set the flags, then paste or type sample text. Matches are highlighted immediately, with the count and a detailed list underneath. Start with the one-click examples if you want to see how a good pattern looks.
Reading the results
- Highlighted text shows every match, alternating two shades so neighbouring matches stay distinct. Empty matches appear as a thin marker.
- Match details list each match with its position, line and column, every numbered group and every named group. A group that did not take part shows as
undefined. - Replace preview applies your replacement to the whole text so you can check a search-and-replace before running it in code.
Flags worth knowing
gfinds all matches, not just the first.iignores letter case.mmakes^and$match at each line.slets the dot match newlines.uturns on full Unicode handling, needed for\p{L}and emoji.yis sticky: each match must start exactly where the last one ended.
Writing patterns that behave
- Anchor patterns with
^and$when validating a whole value, such as a form field. - Prefer specific classes (
[0-9],\d) over a greedy.*, which swallows more than you expect. - Use lazy quantifiers (
.*?) to stop at the first closing delimiter. - Use non-capturing groups
(?:...)when you only need grouping, to keep group numbers tidy. - Escape the special characters
. * + ? ( ) [ ] { } | \ ^ $when you mean them literally.
Avoiding slow patterns
Nested repetition such as (a+)+ can trigger catastrophic backtracking, where the engine tries an exponential number of paths. Keep alternations distinct, avoid repeating a group that can itself match the same text, and test with long, almost-matching input. Never trust a regular expression alone to validate complex formats such as full email addresses; combine it with a sensible length limit and server-side checks.
Frequently asked questions
Which regular expression flavour does this use?
It uses your browser's JavaScript (ECMAScript) engine, so results match what you will get in Node.js, React or any web code. Other languages differ in details such as lookbehind support, possessive quantifiers and inline flags.
Why do I only see one match?
Without the g (global) flag a regular expression stops after the first match. Switch on g to find every match in the text.
What happens with empty matches?
Patterns like x* or ^ can match zero characters. The tester steps forward after each empty match so it never loops forever, and shows them as thin markers in the preview and as "(empty match)" in the list.
How do I use named groups in a replacement?
Write the group as (?<year>\d{4}) in the pattern and reference it as $<year> in the replacement. Numbered groups use $1, $2 and the whole match is $&.
Can a bad pattern freeze the page?
Patterns with nested quantifiers, such as (a+)+$, can take exponential time on some inputs. This tool caps results at 5000 matches but cannot interrupt a single slow match, so keep patterns simple and anchored.
Is my text uploaded anywhere?
No. Matching runs entirely in your browser and nothing is sent or stored, so it is safe to test against logs or private data.