Regex Tester

Test a regex against sample text with live highlighting, capture groups, and find-and-replace — no signup, all in your browser.

/ /
Flags: g (global), i (ignore case), m (multiline), s (dot-all), u (unicode), y (sticky)

Common Patterns

Highlighted Matches

About this tool

What this tool does

Regular expressions are powerful but notoriously easy to get subtly wrong — an off-by-one in a quantifier or a missing escape can silently match the wrong thing. This tester runs your pattern against real sample text as you type, highlights every match directly in the text, breaks out each capture group, and previews what a find-and-replace would actually produce — all client-side, using the same regex engine your browser's JavaScript already runs.

How to use it

  • Type or paste a pattern into the regex field, and set flags (g, i, m, s, u, y) as needed.
  • Paste your test text below — matches highlight live as you edit either field.
  • Scroll down to see each match's index, full matched text, and every capture group broken out individually.
  • Type a replacement pattern (using $1, $2, etc. for capture groups) to preview the find-and-replace result instantly.
  • Click a common pattern — email, URL, IPv4 address, US phone number, hex color, ISO date, HTML tag — to load a battle-tested starting regex instead of writing one from scratch.

Real-world use cases

  • Validating an email or phone input pattern before dropping it into a form's pattern attribute or backend validator.
  • Extracting every URL, hashtag, or hex color code out of a block of scraped text.
  • Debugging why a regex in a script or config isn't matching what you expect, by testing it in isolation against real sample data.
  • Building a find-and-replace regex for a bulk text cleanup or a code refactor, and checking the exact output before running it for real.

Frequently asked questions

What regex flavor does this use?

JavaScript's native RegExp engine (ECMAScript regex) — the same one that powers .match(), .replace(), and .test() in any browser or Node.js script. Syntax is very close to PCRE (used by PHP, Python's re, and most other languages) but not identical, so double-check flavor-specific features like lookbehind support in older engines.

What does the "g" flag do, and why is it always applied for highlighting?

The global flag makes a regex find every match in the text instead of stopping after the first one. This tool always searches globally for the highlighted-matches view so you can see every hit at once, regardless of whether you've added g to the flags field yourself.

How do I reference a capture group in the replacement text?

Use $1 for the first parenthesized group, $2 for the second, and so on — the same syntax JavaScript's String.replace() uses natively.

Why does my pattern show an "Invalid regular expression" error?

Usually an unescaped special character (like a bare (, [, or . that needs a backslash), an unclosed group, or a flag combination the engine doesn't support (like combining u with certain legacy syntax). The error message includes the browser's own explanation of what went wrong.