~ / developer / regex-tester

/.*/ Regex Tester

A regex tester that highlights matches the moment you type. JavaScript (ECMAScript) syntax, with groups, replace preview and a cheat sheet.

/ /
ready.
test string
highlight0 matches
matches & groups
replace
→
cheat sheet — click to insert into the pattern

How to use the regex tester

  1. Type your pattern between the / … / slashes. You don't need to type the slashes yourself.
  2. Toggle the flags g i m s u at the top (g is on by default).
  3. Paste text into test string. Matches are highlighted in the highlight panel and the match count appears in its top-right corner.
  4. The matches & groups table lists each match with its position (@index), numbered groups $1, $2… and named groups <name>.
  5. Type a replacement in replace to preview the result of String.prototype.replace live.
  6. Click any cheat-sheet entry to insert it at the cursor. sample loads an email-extraction example with named groups.

What is a regular expression?

A regular expression (regex) is a compact pattern that describes "strings that look like this." Developers use regex to validate input formats (emails, ZIP codes, phone numbers), pull specific lines out of logs, and run bulk find-and-replace in editors like VS Code. This tester uses your browser's own RegExp engine, so it follows JavaScript (ECMAScript) syntax — the same flavor used in Node.js, TypeScript and most front-end code. Python, Java, PCRE and .NET are very similar but differ in a few details (see the FAQ).

Regex flags

FlagNameWhat it does
gglobalFind all matches (off = stop after the first)
iignore caseCase-insensitive matching
mmultiline^ and $ match at the start/end of every line
sdotAll. also matches line breaks
uunicodeTreats emoji and other astral characters as one character; enables \p{…} property escapes

Common regex patterns

GoalPatternNotes
US phone number\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}Matches (555) 123-4567, 555.123.4567, 5551234567
US ZIP code^\d{5}(-\d{4})?$12345 or ZIP+4 12345-6789
Simple email^[^\s@]+@[^\s@]+\.[^\s@]+$Loose on purpose — confirm with a verification email
Collapse spaces\s{2,} → " "Turns runs of whitespace into one space
Reorder a date(\d{4})-(\d{2})-(\d{2}) → $2/$3/$12026-10-13 → 10/13/2026
Hex color#(?:[0-9a-fA-F]{3}){1,2}\b#fff or #C6FF3D

In the replacement you can use $1 (numbered group), $<name> (named group) and $& (the whole match). The copy button next to the pattern copies a /pattern/flags literal you can paste straight into JavaScript; the copy button on the replace panel copies the full replaced text. If the pattern is invalid, the browser's error message appears in red under it.

Tips

The table shows up to 200 matches and the counter stops at 5,000. Patterns that match an empty string (like a*) are counted but not highlighted. Nested quantifiers such as (a+)+ can cause catastrophic backtracking (ReDoS) and freeze the tab on long input. Your text never leaves the browser.

FAQ

Why does my regex only match once?
The g (global) flag is off, so matching stops at the first hit. Turn on g. If you use ^ or $ across several lines, you also need the m (multiline) flag.
Can I test Python regex here?
Mostly yes — character classes, quantifiers, groups and lookarounds behave the same. Differences: Python named groups are (?P<name>…) while JavaScript uses (?<name>…), and inline flags like (?i) are not supported in JavaScript.
Why does .* match too much?
Quantifiers are greedy by default and take as much as possible. Use the lazy version .*? to get the shortest possible match, or a negated class such as [^"]* to stop at a specific character.
How do I match a literal dot, parenthesis or dollar sign?
Escape it with a backslash: \. \( \) \$. Inside square brackets most special characters are literal, so [.] also matches a dot.
What is the regex for an email address?
There is no perfect one. A practical pattern is ^[^\s@]+@[^\s@]+\.[^\s@]+$ — it rejects obvious typos without blocking real addresses. The only true validation is sending a confirmation email.

Related tools