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
gglobal: find every match, not just the firstiignore case: a matches Ammultiline: ^ and $ match at each line start and endsdotAll: . also matches a line breakuunicode: treat the pattern as code points; enables \p{…}ysticky: each match must start where the previous one ended (the first at the start of the text)
Explain this pattern
| Part | Meaning |
|---|---|
| (?<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
| # | Full Match | Group 1 | Group 2 | Named groups | Start | End |
|---|---|---|---|---|---|---|
| 1 | [email protected] | ada | example.com | user=adadomain=example.com | 8 | 23 |
| 2 | [email protected] | grace.hopper | navy.mil | user=grace.hopperdomain=navy.mil | 25 | 46 |
| 3 | [email protected] | SALES | Example.org | user=SALESdomain=Example.org | 50 | 67 |
3 matches
Quick reference (JavaScript / ECMAScript syntax)
| Syntax | Meaning |
|---|---|
| \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 \B | start 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|b | alternation: 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 match | Pattern | Sample text | Matches (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+\b | 3 apples, 12 pears, 150 plums | 3 (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-01 | 2026-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})?\b | Beverly Hills, CA 90210 and 94103-1234 | 90210 (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
| Flag | Pattern and text | Matches without it | Matches with it |
|---|---|---|---|
| g | [0-9]+ on “Room 12, floor 3” | 12 | 12, 3 |
| i | cat on “Cat cat CAT”, with g | cat | Cat, cat, CAT |
| m | ^\w+ on the lines “one”, “two”, “three”, with g | one | one, two, three |
| s | a.b on “a”, a line break, “b” | none | one, across the line break |
How to use this tool
- Type the pattern, or load one of the eight presets (Email, URL, Phone, IPv4, UUID, Date (ISO), HTML Tag, IP:Port).
- 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.
- Type or paste the text to test. Matches are highlighted in it and listed in a table with their groups and positions.
- Switch to Replace and type a replacement to see the text after substitution.
- 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 toolsJSON Formatter
Paste JSON to format it with 2 spaces, 4 spaces or tabs, minify it or sort its keys. A syntax error is reported with its line, column and a caret under it.
JSON Path Query Tool
Test a JSONPath expression on your JSON and see the match count, each matching value and its path. Filters such as ?(@.price < 10) work. Up to 100 KB.
Base64 Converter
Encode text to Base64 or decode Base64 to text. UTF-8, standard and URL-safe alphabets, optional padding on decode, up to 250,000 characters.
URL Encoder/Decoder
Percent-encode or decode text as you type: one value with encodeURIComponent or a whole URL with encodeURI, and an option to read + as a space.
UUID Generator
Generate 1 to 1,000 random v4 UUIDs, or time-based v1, or name-based v5 and v3 from a namespace and a name, and copy them. Repeats of v4 are very unlikely.
ULID Generator
Generate 1 to 500 ULIDs, 26-character IDs that sort by creation time, in upper or lower case, and decode any ULID to the date it was made.