Regex Tester

Type a regular expression and a test string to see matches highlighted live, with capture groups, named groups and a replace preview. Load ready-made patterns for email, phone numbers, URLs and more.

Matches โ€”

Match list ยท groups

#PositionMatchGroups

No matches found.


  

About the Regex Tester

A regular expression (regex) is a small pattern language for finding or replacing text that follows a rule. It is used for input validation, log analysis and bulk search and replace. This tester runs on your browserโ€™s JavaScript regex engine, so you get exactly the same results as in JavaScript or TypeScript code.

Matching runs in a separate thread (Web Worker). If a bad pattern takes too long, it is stopped automatically after 1.5 seconds and the page never freezes.

How to use

  1. Pick an example from Common patterns or type your own regex. You donโ€™t need the surrounding slashes (/).
  2. Toggle the flags you need (g, i, m, s, u, y).
  3. Enter a test string. Matches are highlighted, and the list below shows each position and group value.
  4. Use $1, $<name> or $& in Replacement to preview the replaced text.

Regex cheat sheet

SyntaxMeaningExample
\d \w \sdigit / letter, digit or _ / whitespace\d{3}
.any character except line breaks (including them with the s flag)a.c
* + ? {n,m}0 or more / 1 or more / 0 or 1 / n to m times\d{3,4}
^ $start / end (of each line with the m flag)^\d+$
[A-Za-z]character class (one of these characters)[A-Z]{2}
( ) (?: )capture group / non-capturing group(\d{4})-(\d{2})
(?<name> )named group(?<year>\d{4})
(?= ) (?! )lookahead / negative lookahead\d+(?=px)

What the flags do

  • g (global): find all matches, not just the first one.
  • i (ignoreCase): ignore upper and lower case.
  • m (multiline): ^ and $ match at the start and end of every line.
  • s (dotAll): the dot (.) also matches line breaks.
  • u (unicode): treat emoji and other astral characters as one character and enable \p{โ€ฆ} property escapes.
  • y (sticky): only try to match at the current position (lastIndex).

Beware of catastrophic backtracking (ReDoS)

Patterns with nested quantifiers such as ^(a+)+$ can take exponential time on input that doesnโ€™t match, which can freeze a server. This is known as a ReDoS attack. If this tester times out, remove the nesting, for example by replacing (a+)+ with a+.

FAQ

Does a regex prove that an email address or phone number is real?

No. A regex only checks the format. Whether an address or number actually exists can only be confirmed by sending a message to it. Nothing you type here is sent to a server.

Are results the same as in Python, Java or PCRE?

The basic syntax is mostly the same, but details differ. Python writes named groups as (?Pโ€ฆ), and in Java string literals you have to double the backslash (\\d). This tester follows JavaScript (ECMAScript).

How do I match whole lines only?

Anchor the pattern with ^ and $ and turn on the m flag, e.g. ^\d+$ with m matches every line that contains only digits.

What happens with a huge number of matches?

Up to 5,000 matches are found and highlighted; the table lists the first 300.