UtiliTools

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.

//g

Highlighted matches

3 matches

Contacts: jane@company.com, john.smith@gmail.com and support@utilitools.dev

#MatchIndexGroups
1jane@company.com10$1: company
2john.smith@gmail.com28$1: gmail
3support@utilitools.dev53$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

  1. Type the regular expression without slashes, such as \d+.
  2. Pick the flags. The g flag finds every match instead of only the first.
  3. Paste your test string. Matches are highlighted instantly.
  4. 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, \d digit, \w letter, digit or _, \s whitespace
  • * 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.

See also:

UtiliTools · by Viniciusadm · 2023 - 2026