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.


  
iPhone app ยท Free to downloadScanner - Scan to PDF, DocsScan paper documents into clean PDFs with your iPhone.View on the App Store

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.

Worked examples

Reformat ISO dates as US dates with named groups

Input
Pattern (?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2}), flag g, replace $<m>/$<d>/$<y>
Text: Invoices: 2026-03-15, 2026-04-01 and 2025-12-31
Result
3 matches, each listed with <y>, <m> and <d>
Replaced: Invoices: 03/15/2026, 04/01/2026 and 12/31/2025

Named groups make the replacement readable and survive edits to the pattern. Use $<d>/$<m>/$<y> instead for day-first formats used in the UK, Australia and most of Europe.

Validate ZIP codes line by line (m flag)

Input
Pattern ^\d{5}(-\d{4})?$
Text (3 lines): 90210 / 10001-1234 / 1234
Result
Flag g only: 0 matches
Flags g+m: 2 matches (90210 and 10001-1234; group $1 is undefined for the first and -1234 for the second)

Without m, ^ and $ anchor to the whole text, so a multi-line list never matches. The optional ZIP+4 group shows as undefined when it did not take part in the match.

A pattern that would hang a server

Input
Pattern ^(a+)+$
Text: 36 letters a followed by !
Result
โฑ Stopped after 1.5 seconds. Nested quantifiers like (a+)+ cause catastrophic backtracking.

In production code this is a ReDoS risk; ^a+$ does the same job instantly. A plain typo such as (\d+ shows "Regex syntax error โ€ฆ Unterminated group" instead.

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<name>โ€ฆ), 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.

How do $1, $<name> and $& work in the replacement?

$1 and $2 insert numbered capture groups, $<name> inserts a group written as (?<name>โ€ฆ), and $& inserts the whole match. Without the g flag only the first match is replaced. To insert a literal dollar sign, write $$.