Regex Tester

Type a pattern and some text to see every match highlighted as you type, with capture groups, positions and a replace preview. Patterns run in a background worker, so a runaway regex cannot freeze the page.

100% freeNo sign-upRuns in your browserWorks on mobile
/ /g
Matches highlighted
$1, $2 or $<name> insert a group, $& the whole match, $$ a dollar sign.
Regex cheat sheet
SyntaxMeaning
.Any character except a line break (any character with the s flag)
\d \w \sA digit, a word character (letter, digit or underscore), whitespace
\D \W \SAnything except a digit, word character or whitespace
[abc] [a-z]One character from the set or range
[^abc]One character that is not in the set
^ $Start and end of the text (of each line with the m flag)
\b \BA word boundary, a position that is not a word boundary
* + ?Zero or more, one or more, zero or one
{3} {2,} {2,5}Exactly 3, at least 2, between 2 and 5
*? +? {2,5}?Lazy versions that match as little as possible
(abc)Capture group, numbered from 1 by its opening parenthesis
(?:abc)Group without capturing
(?<name>abc)Named capture group
\1 \k<name>The same text a group already matched (backreference)
a|bEither a or b
(?=x) (?!x)Followed by x, not followed by x (lookahead)
(?<=x) (?<!x)Preceded by x, not preceded by x (lookbehind)
\p{L} \p{N}Any Unicode letter or number (needs the u flag)
\. \* \\A backslash makes a special character literal

How to use the Regex Tester

  1. Type a pattern without slashes, or pick one from Insert a common pattern. Pasting a literal such as /ab+c/gi fills in the flags too.
  2. Tick the flags you need: g for every match, i to ignore case, m for line-by-line anchors and so on.
  3. Paste your test text. Matches are highlighted as you type, and the table lists each one with its position and capture groups.
  4. Type a replacement using $1 or $<name> to preview the result, then copy it or copy the pattern for your code.

Features

  • Live highlighting of every match as you type
  • Capture groups, named groups and group positions with the d flag
  • Replace preview with $1, $<name> and $& substitutions
  • All JavaScript flags: g, i, m, s, u, y and d
  • Ready-made patterns for emails, URLs, phones, dates, IPs and colors
  • Runs in a background worker with a time limit, so a slow regex never freezes the page

What a regex tester is for

Regular expressions are compact patterns for finding and transforming text: pulling email addresses out of a document, validating a form field, renaming files or rewriting dates. They are also easy to get subtly wrong. A tester lets you try a pattern against real examples and see exactly what it matches before you put it into code. This one uses the JavaScript (ECMAScript) regex engine built into your browser, the same engine that runs RegExp in web pages and Node.js. Patterns written for PCRE, Python or Java are mostly compatible, but details such as lookbehind support and flag names can differ.

The flags

FlagNameEffect
gglobalFind every match instead of stopping at the first
iignore casea also matches A
mmultiline^ and $ match at each line, not just the whole text
sdot all. also matches line breaks
uUnicodeTreats emoji and other astral characters as one character and enables \p{…}
ystickyEach match must begin exactly where the previous one ended
dindicesRecords the start and end position of every capture group

Capture groups and replacements

Parentheses capture the text they match, numbered from left to right by their opening parenthesis. You can name a group with (?<year>\d{4}) to make patterns self-documenting. In the replacement, $1 inserts group 1, $<year> inserts a named group, $& inserts the whole match and $$ writes a literal dollar sign. For example, the pattern (\d{4})-(\d{2})-(\d{2}) with the replacement $2/$3/$1 turns 2026-03-14 into 03/14/2026.

Greedy versus lazy

Quantifiers such as * and + are greedy: they grab as much as they can and give characters back only when the rest of the pattern needs them. Against <b>one</b> and <b>two</b>, the pattern <b>.*</b> matches the entire line in one go. Adding a question mark makes it lazy: <b>.*?</b> stops at the first closing tag and finds two separate matches.

Catastrophic backtracking

When a pattern can match the same text in many different ways, a failed match may force the engine to try every combination, and the work grows exponentially with the length of the input. The classic example is ^(a+)+$ tested against a long run of a’s followed by an exclamation mark. In a web page or a server, that can lock up the browser tab or a request handler; this vulnerability is known as ReDoS. Here the matching runs in a separate worker and is stopped after 1.5 seconds, with a warning. To fix such a pattern, avoid quantifiers nested inside other quantifiers, make alternatives mutually exclusive and anchor the pattern where you can.

Validation patterns are approximations

The ready-made patterns are practical rather than exhaustive. No reasonable regex fully implements the email address grammar, so the email pattern accepts the addresses people actually use; the only real test is sending a message. The IPv4 pattern checks that each part is between 0 and 255, and the date pattern checks ranges but not whether February 30 exists. For bulk extraction from documents, try the Email Extractor, and for simple search and replace without patterns, use Find and Replace.

Frequently asked questions

Which regex flavor does this tester use?

JavaScript (ECMAScript), as implemented by your browser. Current browsers support lookbehind, named groups, the s, u, y and d flags, and Unicode property escapes such as \p{L}.

Why is only one match highlighted?

The g (global) flag is off. Without it, JavaScript stops after the first match. Tick g to find every match.

Why does ^ not match at the start of each line?

By default ^ and $ refer to the start and end of the whole text. Tick the m (multiline) flag to make them match at every line break.

What does “Stopped after 1.5 seconds” mean?

The pattern took too long on your text, almost always because of catastrophic backtracking from nested quantifiers like (a+)+. The page stays responsive because the matching runs in a background worker that is stopped.

Do I need to escape forward slashes?

Not in the pattern box. Slashes only need escaping inside a regex literal in code, such as /https?:\/\//. The Copy as /regex/ button gives you the literal form.

Is my test text sent anywhere?

No. Matching runs in your browser, and the last pattern and text are only remembered in this browser’s local storage.

More developer tools

Other free tools you might need next.

View all 24