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
- Type the expression in "Pattern" without slashes, and press flag buttons such as g, i or m to switch them on or off.
- Put text in "Test string". Matches are highlighted, and the "Matches" tab lists their positions and groups.
- On "Replace", type a group number such as $1 in "Replace with" to see the result. "Split" shows the parts between matches.
- 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
- Matching uses the JavaScript RegExp engine of your browser, so results are the same as in JavaScript code.
- Matching runs in a separate background worker and stops after 1 second. Up to 10,000 matches are found, and the list shows the first 500.
- Nothing you type is saved. A share link carries the pattern and text (the first 4,000 characters) inside the link itself; nothing is uploaded.
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.