Regex Tester

Test, debug and visualise JavaScript regular expressions with live match highlighting and capture groups.

//
Regex Cheatsheet
.Any char except newline (s flag: includes newline)
\dDigit [0-9]
\wWord char [a-zA-Z0-9_]
\sWhitespace (space, tab, newline)
\D \W \SNegated versions of above
*0 or more (greedy)
+1 or more (greedy)
?0 or 1 (or make * + lazy: *? +?)
{n,m}Between n and m repetitions
^ $Start / end of string (m flag: per line)
[]Character class: [aeiou] [a-z] [^0-9]
|Alternation: cat|dog
()Capture group
(?:)Non-capturing group
(?=)Lookahead: foo(?=bar)
(?!)Negative lookahead: foo(?!bar)
(?<=)Lookbehind (ES2018+)
$1 $&In replacement: $1 = group 1, $& = full match

Related Tools

0 comments

How it works

Type a pattern (without slashes) and toggle flags like g, i, m. The tool builds a RegExp via new RegExp(pattern, flags) and runs matchAll on your test string, wrapping each match in a highlighted span. Capture groups are extracted and shown in a table per match. The replacement field uses String.prototype.replace so $1, $2, and $& backreferences work as expected. If your regex is invalid, the exact JavaScript error is shown. Everything runs in your browser — paste private data safely.

Common use cases

  • Validate and debug an email or URL regex before pasting it into production code.
  • Extract fields from log lines using capture groups without writing a script.
  • Build and preview a search-replace transformation (e.g., reformatting dates from MM/DD/YYYY to YYYY-MM-DD).

Frequently asked questions

What regex flavor does this use?

JavaScript (ECMAScript). Flavors differ: lookbehind (?<=) works in modern JS but not older engines; named groups (?<name>) are ES2018+. PCRE or Python patterns may need minor tweaks.

What do the flags do?

g = global (find all matches, not just first). i = case-insensitive. m = multiline (^ and $ match line boundaries). s = dotAll (. matches newlines). u = Unicode mode. y = sticky (match only at lastIndex).

Why does the page lag on a long input?

Certain patterns cause catastrophic backtracking — exponential time for certain inputs. The browser will eventually recover. Avoid nested quantifiers on the same character class, e.g., (a+)+.

How do I match a literal dot or parenthesis?

Escape with backslash: \. matches a literal dot, \( matches a literal open paren. In the pattern field, type the backslash literally — do not double-escape.