Skip to main content
CalcChef

Regex Tester

Test a JavaScript regular expression on your own text: every match with its numbered and named groups and start and end positions, flag switches and replace. How it works

Use the Regex Tester

/
/
Flags:
  • g global: find every match, not just the first
  • i ignore case: a matches A
  • m multiline: ^ and $ match at each line start and end
  • s dotAll: . also matches a line break
  • u unicode: treat the pattern as code points; enables \p{…}
  • y sticky: each match must start where the previous one ended (the first at the start of the text)
Matches
Contact [email protected], [email protected] or [email protected]. Not addresses: @nope, user@, 42@x.
Common Patterns
Explain this pattern
What each part of the pattern means
PartMeaning
(?<user>start of capturing group 1, named "user"
[\w.]any one character from: word character (letter, digit or underscore), "."
+one or more times, as many as possible (greedy): the item before it
)end of the group 1
@the text "@"
(?<domain>start of capturing group 2, named "domain"
[\w-]any one character from: word character (letter, digit or underscore), "-"
+one or more times, as many as possible (greedy): the item before it
\.the character . itself
[a-z]any one character from: "a" to "z"
{2,}2 or more times, as many as possible (greedy): the item before it
)end of the group 2

The explanation follows JavaScript syntax and reads the pattern as written; it does not run it on your text.

Capture Groups

Each match with its index, groups and named groups
#Full MatchGroup 1Group 2Named groupsStartEnd
1[email protected]adaexample.comuser=adadomain=example.com823
2[email protected]grace.hoppernavy.miluser=grace.hopperdomain=navy.mil2546
3[email protected]SALESExample.orguser=SALESdomain=Example.org5067

3 matches

Total
3
Unique
3
Density
51.5%
Avg Length
17.7
Range
8–50

Quick reference (JavaScript / ECMAScript syntax)

JavaScript regular expression syntax
SyntaxMeaning
\d \w \s .digit, word character (letter, digit, _), whitespace, any character except a line break
[abc] [^abc] [a-z]one of a, b, c; none of them; a range
^ $ \b \Bstart of text (or line with m), end of text (or line with m), word boundary, not a word boundary
* + ? {n} {n,m}zero or more, one or more, optional, exactly n, n to m times (greedy)
*? +? ?? {n,m}?lazy versions: match as little as possible
( ) (?: ) (?<name> )capturing group, non-capturing group, named group
\1 \k<name>back-reference to group 1 or to a named group
a|balternation: a or b
(?=x) (?!x)lookahead: followed by x, not followed by x
(?<=x) (?<!x)lookbehind: preceded by x, not preceded by x

Patterns from PCRE, Python or .NET may behave differently here. JavaScript has no possessive quantifiers (a*+), no atomic groups and no \A or \Z anchors (use ^ and $ without the m flag). An inline flag for the whole pattern such as (?i) is not supported; the scoped form (?i:…) works only in recent browsers.

About the Regex Tester

A JavaScript regular expression returns only its first match unless the g flag is set; with g it returns every match. This regex tester runs your pattern on your text with the browser’s own JavaScript engine and lists each match with its numbered groups, named groups and start and end positions. It also has a replace mode, a syntax cheat sheet, a plain-English explanation of each part of the pattern and a share link.

Common regex patterns and what they match

To matchPatternSample textMatches (start–end)
Email-like address[\w.+-]+@[\w-]+(?:\.[\w-]+)+Write to [email protected] or [email protected].[email protected] (9–24), [email protected] (28–48)
Whole number\b\d+\b3 apples, 12 pears, 150 plums3 (0–1), 12 (10–12), 150 (20–23)
Decimal number-?\d+\.\d+Low -4.5, high 19.99, mean 7-4.5 (4–8), 19.99 (15–20)
ISO date\d{4}-\d{2}-\d{2}Due 2026-10-08, paid 2026-11-012026-10-08 (4–14), 2026-11-01 (21–31)
Hex color#(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{3})\b#1A2B3C, #fff and #12345#1A2B3C (0–7), #fff (9–13)
US ZIP code\b\d{5}(?:-\d{4})?\bBeverly Hills, CA 90210 and 94103-123490210 (18–23), 94103-1234 (28–38)
Leading and trailing spaces^\s+|\s+$␣␣padded text␣␣␣␣ (0–2), ␣␣ (13–15)

These are patterns to type or paste into the tester; they are not the same as the preset buttons, which load their own patterns and sample text. Each pattern was run with the g flag. Positions count characters from 0 and the end is one past the last matched character, as in the tester’s Start and End columns. ␣ stands for a space. These patterns find text that has the right shape; they do not prove that an email address or ZIP code exists.

What the g, i, m and s flags change

FlagPattern and textMatches without itMatches with it
g[0-9]+ on “Room 12, floor 3”1212, 3
icat on “Cat cat CAT”, with gcatCat, cat, CAT
m^\w+ on the lines “one”, “two”, “three”, with goneone, two, three
sa.b on “a”, a line break, “b”noneone, across the line break

How to use this tool

  1. Type the pattern, or load one of the eight presets (Email, URL, Phone, IPv4, UUID, Date (ISO), HTML Tag, IP:Port).
  2. Switch flags on and off with the g, i, m, s, u and y chips. For d or v, press the keyboard button next to the chips and type the flags as text.
  3. Type or paste the text to test. Matches are highlighted in it and listed in a table with their groups and positions.
  4. Switch to Replace and type a replacement to see the text after substitution.
  5. Open Explain this pattern for one row per part of the pattern, or press Copy share link to send the pattern, flags and text to someone else.

Frequently asked questions

What does the g flag do in regex?
g means global: find every match and do not stop at the first. On “Room 12, floor 3”, [0-9]+ matches only 12 without g, and both 12 and 3 with it. In replace mode, no g means only the first match is replaced. The tester says so when it is showing the first match only.
Why does my regex work in Python or PCRE but not here?
This tester uses JavaScript (ECMAScript) regular expressions. JavaScript has no possessive quantifiers such as a*+, no atomic groups, no (?i) switch at the start of a pattern (the scoped form (?i:…) works only in recent browsers) and no \A or \Z anchors. Set flags with the chips, and use ^ and $ without the m flag for the start and end of the text.
How do I use a named capture group?
Write (?<name>…) around the part you want. (?<year>[0-9]{4})-(?<month>[0-9]{2}) on “Due 2026-10-08” matches 2026-10 with year = 2026 and month = 10. The tester lists named groups in their own column.
How do I use a group in the replacement?
$1 is the first group, $<name> a named group, $& the whole match and $$ a literal dollar sign. With the g flag, replacing (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) with $<month>/$<day>/$<year> turns “Due 2026-10-08, paid 2026-11-01” into “Due 10/08/2026, paid 11/01/2026”.
What is the difference between greedy and lazy matching?
A greedy quantifier takes as much as it can, a lazy one as little as it can. On “<b>bold</b>”, <.+> matches the whole string, while <.+?> matches <b> and </b> separately. Add ? after a quantifier to make it lazy.
Why was my pattern stopped or refused?
Patterns run in a background worker that is stopped after 1.5 seconds, and a repeated group inside a repeated group, such as (a+)+, is refused before it runs. Both protect the page from patterns whose running time explodes as the text gets longer. Simplify the pattern or shorten the text.

Related Tools

View all tools