MultiTools
Text & Data

Regex Tester

Test, explain and visualize regular expressions.

  • Local by default
  • No signup
  • AI is opt-in
JavaScript flavor

Highlighted matches

 

This tester runs JavaScript regular expressions against your own text, gives every match its own color and number, lists capture groups and previews replacements. A syntax reference covers the common metacharacters, and the Railroad tab draws the paths a match can take — sequences, branches, groups and quantifier loops. Clicking a node selects the matching fragment in the pattern field. The editor, matches, Explain and Railroad tabs are local; the optional AI tab sends your pattern only after you consent.

What happens when you type a pattern

The browser compiles your pattern with the native RegExp engine, so the results match exactly what new RegExp(pattern, flags) would produce in Node or the browser. Matches are collected with exec in a loop, which is why the g flag matters: without it, a pattern can only match once.

Because JavaScript is the engine, some syntax from other flavours will not work. Named groups and lookbehind are supported in modern runtimes; possessive quantifiers, atomic groups and \A anchors are not. If you are writing a PCRE or Python pattern, test it in the language you will actually ship.

Reading capture groups

Parentheses capture: every pair becomes a numbered group, starting at 1, and appears in the groups column of the match table. Naming a group with (?<name>…) does not renumber the others but gives you a readable handle that survives refactoring. If you only need grouping for a quantifier and not the value, use (?:…) — non-capturing groups keep the result set smaller and make replacement strings predictable.

const m = /(?<user>\w+)@(?<domain>[\w.-]+)/.exec("alice@example.com");
m.groups.user;   // "alice"
m.groups.domain; // "example.com"

Greedy versus lazy quantifiers

A quantifier is greedy by default: .* takes as much as it can and then backtracks until the rest of the pattern matches. Adding ? makes it lazy, so it takes as little as possible. That single character changes results on HTML-like input — <.+> swallows an entire line, while <.+?> stops at the first closing bracket.

Lazy is not automatically better. Lazy quantifiers can also backtrack heavily on non-matching input, and the real fix for repeated delimiters is usually a negated class such as <[^>]+>, which cannot overflow the delimiter at all.

How the plain-English explanation works

The Explain tab walks the pattern left to right and describes each construct: anchors, character classes, groups, alternation and quantifiers. It is a syntax parser, not a language model, so it is deterministic and works offline. It explains what the pattern says, not what you meant — if a pattern is wrong, the explanation will faithfully describe the wrong pattern.

Syntax reference: characters and quantifiers

Use this as a quick lookup while reading a pattern. In the field above, write one backslash (\d); inside a JavaScript string literal you need two ("\\d").

  1. . — any character except a line terminator. With the s flag it also matches newlines.
  2. \d / \D — an ASCII digit / any character that is not a digit.
  3. \w / \W — an ASCII word character (letter, digit or underscore) / a non-word character.
  4. \s / \S — whitespace / non-whitespace.
  5. \b / \B — a word boundary / a non-boundary. Both are zero-width: they match a position, not a character.
  6. [abc], [a-z] — one character from the set or range.
  7. [^abc] — one character that is not in the set.

Quantifiers apply to the single atom before them: a character, an escape, a class or a group.

  1. * — zero or more; + — one or more; ? — zero or one.
  2. {3} — exactly three; {2,5} — two to five; {2,} — two or more.
  3. Append ? to make a quantifier lazy: .*? takes as little as possible.
  4. JavaScript has no possessive quantifiers or atomic groups. Use a negated class or a non-backtracking engine when that matters.

Syntax reference: negation and assertions

Regex has no general “opposite” operator. Negation is expressed by a negated class, a negated shorthand or a negative assertion — and each one has a different scope.

  1. \D, \W, \S — the negated forms of \d, \w and \s.
  2. [^...] — a negated character class. [^] matches any character including newlines; it is rarely what you want.
  3. (?!...) — negative lookahead: the text after the current position must not match. It is not consumed.
  4. (?<!...) — negative lookbehind: the text before the current position must not match. Support depends on the browser or runtime.
  5. Negation is local. ^\D+$ rejects a string containing any digit, while \D+ alone simply finds a run of non-digits.

Syntax reference: anchors, groups and flags

  1. ^ / $ — start / end of the string; with the m flag, start / end of a line.
  2. (...) — capturing group; (?:...) — non-capturing group.
  3. (?<name>...) — named capture, readable from match.groups.name.
  4. (?=...) / (?!...) — positive / negative lookahead; (?<=...) / (?<!...) — positive / negative lookbehind.
  5. g — all matches; i — ignore case; m — multiline anchors; s — dot matches newlines; u — Unicode mode, required for \p{...}.
  6. JavaScript also has y (sticky) and d (match indices); this tester exposes the five flags above.

Named groups and lookbehind work in current browsers and Node. Older Safari versions reject lookbehind, so test in the runtime you actually deploy to.

Production pitfalls worth knowing

  1. Catastrophic backtracking. Nested quantifiers like (a+)+b can take exponential time on a near-miss. A single crafted request can pin a CPU core; prefer simpler patterns or a non-backtracking engine (RE2, Rust regex).
  2. Unanchored validation. \d{3} matches inside abc123def. Add ^ and $ — or better, use /(?:^|\s)…$/.test() style checks — when the whole string must match.
  3. Stateful g regexes. A global regex stores lastIndex between calls, so reusing the same object across inputs silently skips matches. Create a fresh regex per call or reset lastIndex.
  4. Escaping twice. Patterns written in a JavaScript string literal need double backslashes ("\\d+"), while the pattern field here needs only one (\d+).
  5. Unicode surprises. Without the u flag, characters outside the BMP are treated as two code units and . behaves unexpectedly with emoji.

AI explanation is optional

The AI (beta) tab is the only part of this page that sends data off your device. It is off by default and runs only after you tick the consent box and press Explain with AI. The request goes through our Cloudflare Worker to Cloudflare Workers AI; no API key is exposed in the page.

  1. Sent: the pattern and active flags. The test string is sent only if you tick the separate box.
  2. Not sent: your name, account, email or any identifier we attach. There are no accounts.
  3. Not stored: we do not log or keep the prompt or the model response, and the endpoint returns cache-control: no-store.
  4. Cloudflare states that standard Workers AI inference has zero data retention and is not used to train models; its own documentation is the authoritative source.

Treat the test string as public if you choose to send it. Do not include passwords, API keys or customer data. If you do not consent, the local Explain tab is still available and makes no network request.

Should you validate email addresses with regex?

Not with a perfect pattern — the full grammar allows quoted local parts and comments that almost no one supports in production. Use a permissive pattern to catch obvious typos, then verify with a confirmation email. The pattern in the example library (^[^\s@]+@[^\s@]+\.[^\s@]{2,}$) is intentionally loose for that reason.

Frequently asked questions

Is it safe to paste sensitive text into this tester?

Yes for the local tabs: matches, Explain and Railroad never leave the browser, and typing produces no network request. The AI tab is the one exception — it sends the pattern, and optionally the test string, to Cloudflare Workers AI only after you tick the consent box and press the button. Leave the test-string box unchecked if the text is sensitive.

Does this page send my pattern to an AI?

Only if you open the AI tab, tick the consent box and press “Explain with AI”. The default editor, matching, Explain and Railroad tabs make no AI request. The AI request contains the pattern and flags; the test string is included only when you enable that option.

What does Cloudflare do with the AI request?

Cloudflare Workers AI processes it to produce the explanation. Cloudflare states that standard inference has zero data retention and that customer content is not used to train models. We do not log or store the prompt or response ourselves. See the AI privacy note linked in the AI tab for the current details.

Does this support PCRE, Python or Go regex syntax?

No. This page uses the browser’s JavaScript RegExp engine. Constructs like atomic groups, possessive quantifiers and recursion are unsupported, and Go’s RE2 engine rejects backreferences entirely. Test in the target language for anything beyond basic syntax.

Why does my pattern not match anything?

Check three things in order: whether the flags are right (case sensitivity, multiline), whether the pattern is anchored when it should not be, and whether backslashes were escaped twice when copied from a string literal. The Explain tab often reveals an unintended literal character.

What does the global (g) flag change?

With g, the engine continues after the previous match, so you get every occurrence and replace works on all matches. Without g, only the first match is returned. This tester forces a global pass for highlighting so you can see all matches at once.

Can it explain a regex written by someone else?

Yes, that is the point of the Explain tab. It parses the syntax construct by construct and describes each piece. It will not tell you whether the pattern is correct for your data — use the highlighted matches for that.

Why does \w not match accented letters?

\w is defined as ASCII letters, digits and underscore. With the u flag, \p{L} matches any Unicode letter and \p{Script=Han} matches Han characters. Without u, accented letters need an explicit class or a different pattern.