Free tool · runs in your browser
Regex tester
Test a regular expression against your text and see every match, its position and captured groups, with an optional replacement.
Uses the JavaScript regex engine in your browser. Shows up to 100 matches.
Quick answer
Type a regular expression, choose flags and paste your text. The tester lists every match with its position and captured groups, and shows the result of a replacement where $1 means group 1. It uses your browser's JavaScript engine, so what works here works in JavaScript and TypeScript; most simple patterns also work in Python, Java and PHP.
How to use it
- Type the pattern. Without the surrounding slashes, for example \d{3}-\d{4}.
- Pick flags and paste text. g finds all matches, i ignores case, m makes ^ and $ match each line.
- Read the matches. Each match shows its position and groups; add a replacement to see the changed text.
Example
Finding email addresses and capturing the name and domain:
Input
Pattern: (\w+)@(\w+)\.com Flags: g
Text: mail sara@example.com or ali@test.comOutput
2 matches
1. sara@example.com @5 $1=sara $2=example
2. ali@test.com @25 $1=ali $2=testCommon errors and how to fix them
Invalid regular expression: Unterminated group- A ( has no matching ). Count the brackets, or escape a literal bracket as \(.
Invalid regular expression: Nothing to repeat- A quantifier such as *, + or ? has nothing before it, as in *abc. Escape it as \* to match the character itself.
Only the first match is found- The g flag is off. Tick g to find every match.
The page freezes- Nested quantifiers such as (a+)+$ cause catastrophic backtracking on text that almost matches. Remove the nesting or make the pattern more specific.
Frequently asked questions
What do the flags g, i, m, s and u mean?
g finds all matches instead of the first; i ignores case; m makes ^ and $ match at line starts and ends; s lets . match newlines; u enables full Unicode matching.
Why does my regex only find one match?
Without the g flag, JavaScript stops after the first match. Tick g.
How do I match an email address?
A practical pattern is [\w.+-]+@[\w-]+\.[\w.]+ . Fully validating every possible email with regex is not practical; send a confirmation email instead.
How do I use a captured group in a replacement?
Wrap part of the pattern in parentheses and use $1, $2 and so on in the replacement. Named groups (?<year>\d{4}) are used as $<year>.
How do I match a literal dot or bracket?
Escape it with a backslash: \. matches a dot, \( a bracket. Without the backslash, . matches any character.
What is the difference between .* and .*?
.* is greedy and matches as much as possible; .*? is lazy and matches as little as possible. Use the lazy form to stop at the first closing tag or quote.
What is a lookahead?
A check that does not consume text: \d+(?= USD) matches a number only if " USD" follows. (?! ) is the negative version.
Does this work for Python regex?
Mostly. The basic syntax is the same; differences include named groups, written (?P<name>) in older Python, and some flags.
Why does the page freeze with some patterns?
Nested quantifiers such as (a+)+ can take exponential time on text that almost matches. This is called catastrophic backtracking; simplify the pattern.
Is my text uploaded?
No. The regex runs in your browser.