Regex Tester
Test regular expressions in real time. See matches highlighted in your text, the capture groups of each match and the result of a replacement, using the same regex engine as JavaScript.
Highlighted matches
3 matchesContacts: jane@company.com, john.smith@gmail.com and support@utilitools.dev
| # | Match | Index | Groups |
|---|---|---|---|
| 1 | jane@company.com | 10 | $1: company |
| 2 | john.smith@gmail.com | 28 | $1: gmail |
| 3 | support@utilitools.dev | 53 | $1: utilitools |
What is regex?
A regex, or regular expression, is a text pattern used to search, validate and replace parts of a string. A single line can find every email address in a document, validate a ZIP code or reformat dates. Regex works in almost every language, including JavaScript, Python, Java, PHP and Go, and in editors such as VS Code.
How to test a regex
- Type the regular expression without slashes, such as
\d+. - Pick the flags. The
gflag finds every match instead of only the first. - Paste your test string. Matches are highlighted instantly.
- Optionally fill in the replacement to preview the final text.
Useful regex examples
- US ZIP code:
^\d{5}(-\d{4})?$ - Date mm/dd/yyyy:
^\d{2}/\d{2}/\d{4}$ - Hex color:
^#([0-9a-fA-F]{3}){1,2}$ - Digits only:
^\d+$ - Repeated spaces:
\s{2,}
Syntax cheat sheet
.any character,\ddigit,\wletter, digit or _,\swhitespace*zero or more,+one or more,?optional,{n,m}between n and m times^start,$end,[abc]one of the characters,(...)capture group
Frequently asked questions
Which regex flavor does this tester use?
JavaScript (ECMAScript). It is compatible with most regex from Python, Java, PHP and C#, with small differences in advanced features.
What does the g flag do?
The g (global) flag finds every match. Without it, only the first match is used for searching and replacing.
How do I use groups in the replacement?
Wrap parts of the regex in parentheses and use $1, $2 and so on in the replacement field. amp; inserts the whole match.
Do I need to escape backslashes?
Not in this field. Type the regex as you would between slashes in JavaScript, for example \d+. You only double backslashes when the regex lives inside a string in your code.
What regex validates an email address?
A simple, practical one is ^[\w.+-]+@[\w-]+\.[\w.]+$. Fully validating email with regex is impractical, so confirm addresses with a verification email.