Regex Tester

Test regular expressions live, highlight every match, and understand what they do.

Runs in your browserUpdated Built and maintained by Leon and Henrik

Test regular expressions live, see every match highlighted, and preview replacements — privately in your browser. Free. No sign-up. Runs in your browser, nothing is uploaded.

Regex Tester

Matches highlighted

Enter a test string to see matches highlighted here.

0 matches

Replace

Use $1, $<name>, or $& for the whole match.
Type a replacement above to see the result here.

Quick reference

.Any character except newline
\dDigit (0–9)
\wWord character (a–z, A–Z, 0–9, _)
\sWhitespace (space, tab, newline)
\bWord boundary
^ $Start / end of line (or string)
* + ?0+ / 1+ / 0 or 1 (greedy)
*? +?Lazy versions (as few as possible)
{2,4}Between 2 and 4 repetitions
[abc]Any one of a, b or c
[^abc]Any character except a, b or c
(…)Capture group
(?:…)Non-capturing group
(?<name>…)Named capture group
a|ba or b (alternation)
(?=…)Lookahead
(?<=…)Lookbehind
Runs in your browser
Nothing is uploaded

Type a pattern between the slashes, toggle flags, and paste text below: every match lights up in place, and the match list shows each one's position plus its numbered and named groups. Type a replacement to preview a search-and-replace and copy the result. If the pattern is invalid, the engine's own error message appears under the input. Sample loads a working email pattern; the cheatsheet beside it covers the tokens you'll reach for most.

Worked example: reformat dates with named groups

Turn ISO dates (2026-11-30) into the day-first format used across most of Europe (30.11.2026):

  • Pattern: (?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2})
  • Flags: g
  • Replacement: $<d>.$<m>.$<y>

On the text 2026-11-30, 1999-01-05 the preview shows 30.11.2026, 05.01.1999, and the match list shows y, m and d for each date. Named groups make the replacement readable months later; with numbered groups the same thing is $3.$2.$1, which is easier to get wrong. Paste the before and after into the text diff to review every change.

JavaScript regex vs Python, PCRE and Go

Patterns copied from Stack Overflow often come from another engine. The differences that matter most:

FeatureJavaScript (this tester)Python rePCRE (PHP, many editors)Go (RE2)
Named group(?<name>…)(?P<name>…)Both forms(?P<name>…) and (?<name>…)
Group in replacement$1, $<name>\1, \g<name>$1 or \1${1}, ${name}
LookbehindAny lengthFixed width onlyFixed width (limited variable in newer versions)Not supported
LookaheadYesYesYesNot supported
Backreference in pattern (\1)YesYesYesNot supported
Possessive ++ / atomic groupsNoYes, since 3.11YesNo
Start / end of string anchors^ $ without m flag\A \Z\A \z\A \z

Go's engine trades features for a guarantee: it never backtracks, so no pattern can hang it. JavaScript, Python and PCRE make the opposite trade.

The six flags in one line each

FlagEffect
g (global)Find every match, not just the first. On by default here.
i (ignore case)cat also matches Cat and CAT.
m (multiline)^ and $ match at every line start and end, not only the whole text's.
s (dotall). also matches newlines.
u (unicode)Treat emoji and other characters outside the basic plane as one character; enables \u{…} escapes.
y (sticky)Each match must start exactly where the previous one ended — for tokenizers.

Five reasons a pattern matches the wrong thing

  1. Greedy quantifiers. <.+> on <b>bold</b> and <i>it</i> matches the entire line, because .+ grabs as much as it can. The lazy <.+?> matches each tag separately.
  2. Missing anchors. \d{5} "validates" a five-digit postcode — and also accepts 123456789, because five digits appear inside it. For a whole-value check, use ^\d{5}$.
  3. An unescaped dot. 3.4 matches 3.4, but also 3x4 and 3-4. Write 3\.4 for a literal dot.
  4. Forgetting the m flag. Without it, ^ only matches at the very start of the text, so a pattern meant for each line finds just one match.
  5. Catastrophic backtracking. Nested quantifiers like (a+)+$ can take exponential time on text that almost matches: against a run of a's followed by a b, the engine tries every way to split the a's between the inner and outer +, and that number doubles with each extra a. This tester runs the pattern in a background worker and stops it after 1.5 seconds with a warning, so the page stays usable — but your production code has no such guard. If you see that warning, avoid nesting a quantifier inside another on the same characters.

Two practical notes: the match list shows the first 200 matches (the highlight still covers all of them), and the replacement preview appears once the replacement field has something in it. To preview deleting matches, replace them with a visible marker like [x] first.

Patterns people copy — and where they stop working

  • Email: [^\s@]+@[^\s@]+\.[^\s@]+ accepts nearly every real address and rejects obvious typos. A fully standards-compliant email regex is enormous; for sign-ups, a loose check plus a confirmation email works better.
  • URL in text: https?:\/\/[^\s]+ finds links, but also swallows a trailing period or bracket. For strict validation, use the browser's URL constructor instead of a regex.
  • Numbers: -?\d+(\.\d+)? matches integers and decimals, not 1e6, 1,000 or 1.000,50.
  • Collapse whitespace: \s+ with g, replaced by a single space.

Regex recognizes shapes, not meaning. For anything security-relevant, validate with a parser as well — and for routine jobs like turning a title into a URL-safe slug, a purpose-built tool is less brittle than a pattern.

Frequently asked questions