Regex Tester

Test regular expressions online with live match highlighting, capture groups and a replace preview. Uses the JavaScript regex engine.

Regular expression
Matches

How to test a regular expression

  1. Type the pattern between the slashes, without adding slashes yourself. Backslashes are written once: \d, not the \\d you would need inside a string literal in code.
  2. Tick the flags you need. The ones you choose appear after the closing slash, so the line reads exactly like a JavaScript regex literal: /pattern/flags.
  3. Paste your sample into Test string. Matches are highlighted in alternating colors so neighboring matches stay distinguishable, and the status line counts them.
  4. Check the table: every match with its start Index (counted from 0) and the contents of each capture group. A dash means the group did not take part in that match.
  5. Optionally type a replacement to preview a search-and-replace on the whole text. To compare the before and after versions line by line, paste both into the Diff Checker.

If the pattern has a syntax error, such as an unclosed bracket, the browser’s error message is shown instead of results.

The flags

  • g · global – find every match. Without it, only the first match is listed and only the first occurrence is replaced.
  • i · ignore case – order also matches “Order” and “ORDER”.
  • m · multiline – ^ and $ match at the start and end of every line instead of only the whole text.
  • s · dot all – . also matches line breaks.
  • u · unicode – treats characters outside the Basic Multilingual Plane, such as emoji, as one character, and enables property escapes such as \p{L}. It also makes the syntax stricter, so some sloppy escapes become errors.

Worked examples

Capture groups and replacement

The pattern loaded on this page, (\w+)@(\w+)\.com, finds [email protected] at index 8 and [email protected] at index 29, with groups “alice”/“example” and “bob”/“test”. [email protected] is skipped because it doesn’t end in .com. Replacing with $1 at $2 gives “Contact alice at example or bob at test.”

Reformatting dates

Pattern (\d{4})-(\d{2})-(\d{2}) with the g flag and replacement $3/$2/$1 turns “Due 2026-11-05, paid 2026-12-01” into “Due 05/11/2026, paid 01/12/2026”. With named groups, (?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2}) and $<d>.$<m>.$<y>, the replacement explains itself: “05.11.2026”.

Greedy versus lazy

On <b>bold</b> and <i>italic</i>, the greedy pattern <.+> produces one match covering the entire line, because .+ grabs as much as it can. Adding a question mark, <.+?>, makes it lazy, and you get four separate tags.

Letters in any language

\w only covers A–Z, a–z, 0–9 and the underscore, so \w+ breaks “Café Zürich” into “Caf”, “Z” and “rich” and ignores 서울 and 東京 entirely. With the u flag, \p{L}+ matches whole words in every script: “Café”, “Zürich”, “서울”, “東京”.

Cheat sheet

.Any character except a line break (any at all with the s flag)
\d \w \sDigit · letter, digit or underscore · whitespace
\D \W \SThe opposite of each of the above
[abc] [^abc] [a-z]One of the listed characters · anything else · a range
* + ? {2,5}0 or more · 1 or more · optional · between 2 and 5
*? +?Lazy versions: match as little as possible
^ $ \bStart · end · word boundary
(…) (?:…) (?<name>…)Capture group · group without capturing · named group
(?=…) (?!…) (?<=…)Followed by · not followed by · preceded by
$1 $<name> $& $$In the replacement: group 1 · named group · the whole match · a literal $

Common pitfalls

  • Forgetting to escape special characters. In example.com the dot matches any character, so “examplexcom” matches too. Write example\.com.
  • Empty matches. Patterns that can match nothing, like x*, match at every position: on “abc” that is 4 empty matches. They are counted but have nothing to highlight.
  • Catastrophic backtracking. Nested repetition such as (a+)+$ can take exponential time when the text almost matches, which can freeze the browser tab. Make the inner part more specific or remove the nesting.
  • Assuming another language behaves the same. This page runs your browser’s JavaScript engine, so results match match, matchAll and replace in JavaScript and TypeScript. Python writes named groups as (?P<name>…) and replacements as \1 or \g<name>; PCRE and Java support possessive quantifiers and atomic groups, which JavaScript does not.

FAQ

How many matches are shown?

Up to 10,000 matches are found and highlighted, and the table lists the first 500 so the page stays responsive.

Why does my pattern match in this tester but not in my code?

Usually because of escaping. In a JavaScript string, "\d" loses its backslash; write "\\d" or use a regex literal. Also check that your code uses the same flags.

Can I validate email addresses with a regex?

Only loosely. A simple check such as ^[^\s@]+@[^\s@]+\.[^\s@]+$ catches typos; the only real test is sending a confirmation email.

How do I match across several lines?

Use [\s\S], or tick the s flag so . includes line breaks. To anchor each line separately instead, tick m.