Regex Tester
runs in your browserno sign-upfree
Test regular expressions live: matches highlighted, replace and split, a plain-English explanation, and ready-to-use code for JavaScript, PHP, Python and Java.
3 matches
Match details
| # | Match | Position | Groups |
|---|---|---|---|
| 1 | support@example.com | 14–33 | $1 support $2 example.com user support domain example.com |
| 2 | sales.team@example.co.in | 37–61 | $1 sales.team $2 example.co.in user sales.team domain example.co.in |
| 3 | info@old-site.org | 76–93 | $1 info $2 old-site.org user info domain old-site.org |
Explanation
(?<user>[\w.+-]+)capture group 1 named "user"[\w.+-]+a character from a word character (letter, digit or _), ".", "+" or "-", one or more times, as many as possible
@the character "@"(?<domain>[\w-]+(?:\.[\w-]+)+)capture group 2 named "domain"[\w-]+a character from a word character (letter, digit or _) or "-", one or more times, as many as possible(?:\.[\w-]+)+a group (not captured), one or more times, as many as possible\.the character "."[\w-]+a character from a word character (letter, digit or _) or "-", one or more times, as many as possible
- g — find all matches, not just the first
Code
The tester runs your browser’s JavaScript engine; the code is converted for each language. Literal: /(?<user>[\w.+-]+)@(?<domain>[\w-]+(?:\.[\w-]+)+)/g
- .
- Any character except a new line
- \d \w \s
- Digit, word character (a–z, 0–9, _), whitespace
- \D \W \S
- Not a digit / word character / whitespace
- [abc] [^abc] [a-z]
- One of, none of, a range
- ^ $
- Start and end of the text (or line, with m)
- \b
- Word boundary
- * + ?
- 0 or more, 1 or more, 0 or 1
- {3} {2,5} {2,}
- Exactly 3, 2 to 5, 2 or more
- *? +?
- As few as possible (lazy)
- (abc)
- Capture group — $1, $2…
- (?<name>abc)
- Named capture group
- (?:abc)
- Group without capturing
- a|b
- a or b
- (?=abc) (?!abc)
- Followed by / not followed by
- (?<=abc) (?<!abc)
- Preceded by / not preceded by
- \. \* \\
- Escaped special characters
About this tool
This regex tester checks a regular expression against your text as you type. In Match mode every match is highlighted and listed with its capture groups; Replace shows the text with $1 or $<name> replacements; Split breaks the text apart; and Test list checks one value per line — ideal for validation patterns. Underneath, each part of the pattern is explained in plain English, and ready-to-paste code is written for JavaScript, PHP, Python and Java. Share a link to show someone your regex.
How to use
- Type your regular expression between the slashes, without the surrounding / /.
- Tick the flags you need — g to find every match, i to ignore case, and so on.
- Choose a mode: Match, Replace (type the replacement), Split or Test list.
- Paste your test text. Read the explanation, then copy the code for your language.
FAQ
Does the PHP or Python code behave exactly the same?
The tester runs the JavaScript regex engine, and the code is converted for each language: PHP gets / delimiters and $1 / ${1} replacements, Python gets raw strings, (?P<name>…) groups and \g<1> replacements, Java gets doubled backslashes. Everyday syntax works the same everywhere; notes appear when something differs, such as named groups in Python or lookbehind in Java.
What is the Test list mode for?
Put one value per line — emails, phone numbers, IDs — and see at a glance which ones the pattern accepts. Add ^ at the start and $ at the end of your pattern so a value must match completely, not just contain a match.
Why does it only find the first match?
Without the g (global) flag, JavaScript stops at the first match — the tester shows exactly what your code would do. Tick "g — all matches" to find every match.
Will my regex work the same in PHP, Python or Java?
Most everyday syntax — \d, \w, [a-z], groups, quantifiers and lookaheads — is the same everywhere. Some features differ: for example PHP uses preg_match_all() instead of the g flag, and named groups are written (?P<name>…) in older Python code. Test in your own language for advanced patterns.
What are capture groups?
Parentheses ( ) capture the part of the match inside them, so you can use it separately — as $1, $2… in a replacement, or match[1] in code. (?<name>…) gives a group a name, and (?:…) groups without capturing.
The page froze with my pattern — why?
Some patterns, such as (a+)+b, can take extremely long on certain text ("catastrophic backtracking"). Avoid nesting repeats like (x+)+ and make patterns as specific as possible.