DevKit

Regex Tester

Write a pattern, watch matches highlight instantly, and inspect every capture group.

Free No sign-up Runs in your browser
Highlighted matches0 matches
Replace preview

Test the pattern, not your assumptions

Regular expressions are compact, powerful and almost impossible to read back with confidence. The only reliable way to know what a pattern does is to run it against real input and look at what it matched — and, just as importantly, at what it skipped.

The most common bug is a pattern that is too permissive: \S+@\S+ matches a@b and also not-an-email@. Anchoring with ^ and $, or using word boundaries \b, usually fixes it.

Greedy, lazy and catastrophic backtracking

Quantifiers are greedy by default: <.+> against <a><b> matches the whole string, not the first tag. Adding ? makes it lazy — <.+?> stops at the first >.

Lazy quantifiers are not a cure-all. Nested quantifiers such as (a+)+$ can make the engine explore exponentially many ways to divide the input; a 30-character string can take minutes. This is a regular-expression denial-of-service (ReDoS), and it is a real vulnerability when the pattern runs on a server. Prefer unambiguous constructs, bound the repetition, or use RE2-style engines that guarantee linear time.

Flags that change everything

  • g — find all matches instead of the first. It also makes lastIndex stateful, which is why reusing a global regex can produce alternating results.
  • i — case-insensitive.
  • m — ^ and $ match at every line break, not just the start and end of the string.
  • s — dot matches newlines (dotAll). Without it, . stops at a line break.
  • u — Unicode mode: code points instead of UTF-16 units, and stricter escape rules. Essential when emoji or CJK text is involved.

Capture groups in the replace preview

Parenthesised groups are numbered left to right and can be reused in the replacement string as $1, $2, with $& standing for the whole match. Named groups — (?<year>\d{4}) — are clearer in long patterns and become $<year> in replacement.

Frequently asked questions

Which flavour of regex is this?
JavaScript (ECMAScript). It is close to PCRE but differs: no (?>...) atomic groups, no possessive quantifiers, and some lookbehind restrictions in older engines.
Why does my global regex return different results on each call?
A /g regex keeps lastIndex between calls. Reset it, avoid sharing the instance, or use String.prototype.matchAll instead.
My pattern is very slow on long input.
Nested quantifiers like (a+)+ cause exponential backtracking. Rewrite to avoid ambiguity, or use a linear-time engine such as RE2 or the re2 npm package.
Can I use this for email validation in production?
Use a regex only to reject obvious garbage, then verify by sending a confirmation email. The "perfect" email regex is enormous and still rejects addresses that are technically valid.

Related tools