Skip to content

Regex Tester

Write a regular expression and test string, toggle flags, and see live matches, capture groups and match counts.

Runs locally in your browser

2 matches
hello@example.comsupport@example.com

Highlighted text

Contact us at hello@example.com or support@example.com today.

Replacement preview

Contact us at [email] or [email] today.

Discuss a result

Write a short summary and review it before posting. Your tool inputs are never copied automatically.

What is the Regex Tester?

This tester evaluates a JavaScript regular expression against sample text and highlights every match and capture group in real time.

How to use it

  1. 1Enter a pattern and toggle flags (g, i, m, s, u).
  2. 2Type or paste a test string.
  3. 3Review highlighted matches and captured groups.

How it works

The pattern is compiled with the RegExp constructor using your flags, then run against the input. Invalid patterns show a syntax error instead of crashing.

Limitations & notes

  • Uses JavaScript regex semantics, which differ from PCRE, .NET and RE2.
  • Catastrophic backtracking in a pattern can be slow — this runs on your machine.

Frequently asked questions

Why does my regex work here but not in Python, PHP or grep?

Regex engines differ. This tester uses JavaScript's engine, which lacks possessive quantifiers like a++, atomic groups, and the \A and \Z anchors found in PCRE and Python. Python names groups with (?P<name>...) while JavaScript uses (?<name>...). Basic grep does not understand \d at all. Test in the same flavor your code will use, or stick to common syntax such as character classes, groups and quantifiers.

How do I use capture groups in the replacement text?

The replacement field follows JavaScript's String.replace rules. Use $1, $2 and so on for numbered groups, $<name> for a named group, $& for the whole match and $$ for a literal dollar sign. For example, the pattern (\w+)@(\w+) with replacement $2 at $1 turns hello@example into example at hello. The replacement preview updates as you type, so you can check the result before copying.

Why does this tester always find every match even without the g flag?

The tool adds the g (global) flag automatically so it can list all matches and highlight them, and the replacement preview therefore replaces every occurrence. In your own code, without g, methods like replace and match stop after the first hit. If you want to see only the first match, read the first item in the match list. Up to 500 matches are listed.

What do the i, m, s and u flags change?

i ignores case, so /cat/i matches Cat. m makes ^ and $ match at the start and end of every line instead of the whole text. s lets the dot also match newline characters. u enables full Unicode mode, so an emoji counts as one character and escapes like \p{L} for any letter work. Type flags as letters together in the flags box, for example gim.

Why is my pattern slow or freezing the page?

Nested quantifiers such as (a+)+$ or (.*)* can cause catastrophic backtracking, where the engine tries an exponential number of ways to match before failing. On a 30-character string that can mean billions of steps. Rewrite the pattern to remove ambiguity, for example a+$ instead of (a+)+$. To keep the page usable, this tester refuses patterns over 1,000 characters and test text over 100,000 characters.

No directly related discussion yet.

Start a focused thread and share the question this tool helped you explore.

Ask the community about Regex Tester

You might also like