Skip to content

Regex Tester

Test a regular expression live: see matches, capture groups and replacements

Loading the tool…

Enter a regular expression and a test string to see the matches highlighted at once, with the position and group values of each match. Use it to check that a pattern matches what you expect, and that a replacement gives the right result, before you put it in code.

How to use

  1. Type the expression in "Pattern" without slashes, and press flag buttons such as g, i or m to switch them on or off.
  2. Put text in "Test string". Matches are highlighted, and the "Matches" tab lists their positions and groups.
  3. On "Replace", type a group number such as $1 in "Replace with" to see the result. "Split" shows the parts between matches.
  4. Pick an example under "Common patterns" or open "Syntax summary" to look up a symbol. "Copy share link" lets someone else open the same pattern and text.

How it works

Questions and answers

Why does my regex only find the first match?
Without the g flag, only the first match is found. Switch on the g button to find all matches.
How do I use a capture group in a regex replacement?
$1 and $2 are numbered groups and $& is the whole match; a named group is written as $ followed by its name in angle brackets. Replacing (\d{4})-(\d{2})-(\d{2}) with $3.$2.$1 turns 2024-03-15 into 15.03.2024.
What is a regex for email addresses?
The "Email (simple)" example is [\w.+-]+@[\w-]+(?:\.[\w-]+)+. It finds common addresses but does not check every rule of the email standard.
Is JavaScript regex the same as Python or Java regex?
The basic syntax is mostly the same, but details differ. For example, a named group starts with (?< in JavaScript but with (?P< in Python.
What does "Stopped after 1 s" mean?
Patterns with nested quantifiers such as (a+)+ can try a huge number of combinations on text that does not match. Make the inner part more specific or remove the nesting.