Regex Tester (JavaScript Regular Expressions)
Developer ToolsWrite a regular expression and see every match in your test text as you type, with capture groups, replace and a token-by-token explanation.
(start of capture group 1\da digit (0–9){3}repeats the previous item exactly 3 times)end of the group-the character "-"(start of capture group 2\da digit (0–9){3}repeats the previous item exactly 3 times)end of the group-the character "-"(start of capture group 3\da digit (0–9){4}repeats the previous item exactly 4 times)end of the group
Cheat sheet (JavaScript syntax)
- \d \w \s
- digit, word character, whitespace
- \D \W \S
- not a digit, not a word character, not whitespace
- .
- any character except a line break
- [abc] [^abc] [a-z]
- one of, none of, a range
- ^ $ \b
- start, end, word boundary
- * + ? {3} {2,5}
- 0+, 1+, optional, exactly 3, 2 to 5
- *? +? ??
- lazy: as few as possible
- (…) (?:…) (?<name>…)
- capture, group only, named capture
- (?=…) (?!…)
- followed by, not followed by
- (?<=…) (?<!…)
- preceded by, not preceded by
- \1 \k<name>
- repeat what a group captured
- $1 $<name> $&
- in replacements: group 1, named group, whole match
Processed in your browser. A copy of each run is saved to your past runs so you can reopen it. Privacy
About
What the Regex Tester does
The Regex Tester runs a JavaScript regular expression against your test text as you type, highlights every match, lists the capture groups and shows what a replacement would produce. A plain-English explanation breaks the pattern into its tokens, and a cheat sheet covers the syntax. Matching runs in a background worker with a two-second limit, so a runaway pattern cannot freeze the page. It uses the JavaScript engine only; Python, PCRE and Java differ in places.
Steps
How to use it
- 1Type the pattern between the slashes. The sample matches US phone numbers.
- 2Turn on the flags you need: g for every match, i to ignore case, m for line-by-line ^ and $.
- 3Paste your test text. Matches are highlighted and listed with their groups as you type.
- 4Turn on Replace to preview a substitution with $1 or $<name>, then copy the regex as a JavaScript literal or share a link.
Example
A real run
Input
Pattern: (\d{3})-(\d{3})-(\d{4}) Flags: g
Text: Call 512-555-0147 or 214-555-0199. Fax: 737-555-0123.Output
3 matches 1. "512-555-0147" at index 5: $1 = 512, $2 = 555, $3 = 0147 2. "214-555-0199" at index 21: $1 = 214, $2 = 555, $3 = 0199 3. "737-555-0123" at index 40: $1 = 737, $2 = 555, $3 = 0123
Three groups of three, three and four digits capture the area code, prefix and line number of each US phone number. With Replace on and ($1) $2-$3 as the replacement, the text becomes Call (512) 555-0147 or (214) 555-0199.
Options
Every setting, and when to use it
- Flags g, i, m, s, u, y
- g finds every match instead of the first; i ignores case; m makes ^ and $ match at each line break; s lets . match line breaks; u enables full Unicode and \p{…} classes; y (sticky) matches only at the current position. The literal shown beside the pattern updates as you toggle them.
- Match list
- Every match with its position in the text and its capture groups, numbered ($1, $2) and named (?<area>…). Up to 10,000 matches are listed; the count says when that cap was reached.
- Replace
- Shows the whole text after String.replace with your pattern and replacement. Use $1 for a numbered group, $<name> for a named group and $& for the whole match. Without the g flag only the first match is replaced, exactly as in JavaScript.
- Explanation
- Breaks the pattern into tokens and says what each does in plain English, for example "\d: a digit (0–9)" and "{3}: repeats the previous item exactly 3 times". Useful for reviewing a pattern someone else wrote.
- Copy as JS literal and Share link
- Copy as JS literal gives /pattern/flags ready to paste into code. Share link puts the pattern, flags, test text and replacement into the URL fragment after #, which browsers never send to a server, and copies the link.
Good to know
Common problems and limits
This is the JavaScript (ECMAScript) regex engine as your browser implements it. Other engines differ: Python names groups (?P<name>…) where JavaScript uses (?<name>…); PCRE and Java support possessive quantifiers (a++) and atomic groups, which JavaScript does not; \A and \Z anchors do not exist in JavaScript; and inline flags such as (?i) are PCRE and Python syntax.
Matching stops after two seconds with "Stopped after 2000 ms". That almost always means catastrophic backtracking, typically nested quantifiers such as (a+)+ or (.*)* meeting a long string that almost matches. Make the inner part more specific or anchor the pattern.
The test text is limited to 1 MB and the match list to 10,000 entries. An invalid pattern shows the engine's own message, for example "Unterminated group".
Each test is recorded in your past runs when you leave the field, copy or share, not on every keystroke. Avoid pasting real personal data into the test text.
Audience
Who uses it
- DevelopersBuild and check a validation pattern for a form field (ZIP code, phone, SKU) before it goes into code.
- Data and operations teamsExtract order numbers or email addresses from a pasted export, then reshape the results with the case converter or check differences with Text Compare.
- QA engineersConfirm a log-matching pattern catches the lines it should, and none it should not, before adding it to an alert.
- Recruiters and HR operationsPull candidate emails or phone numbers out of a block of pasted text in one step.
- StudentsRead the token-by-token explanation to learn what each part of a pattern does.
FAQ
Frequently asked
How do I check if a string matches a regex?
Paste the string into the test text and type the pattern: matches are highlighted immediately and the status line says how many there are. In JavaScript code the same check is /pattern/.test(text), which returns true or false; add ^ and $ around the pattern to require the whole string to match.
What does ?: mean in a regex?
(?:…) is a non-capturing group. It groups part of a pattern, for example so a quantifier applies to several characters, without saving what it matched as $1 or $2. Use it when you need grouping but not the captured text; it keeps group numbers simple.
What does $ match in a regex?
$ matches the end of the input, so cat$ finds cat only at the very end. With the m (multiline) flag it also matches just before each line break, so it marks the end of every line. In a replacement string, $1 or $<name> instead inserts a captured group.
What does a regex tester do?
It runs a regular expression against sample text and shows what matches, so you can see the effect of each change before the pattern goes into code. This one also lists capture groups, previews replacements, explains each token and stops patterns that run too long.
Is JavaScript regex the same as Python regex?
Mostly, but not entirely. Named groups are (?<name>…) in JavaScript and (?P<name>…) in Python; Python's re module has no \p{…} Unicode classes, while JavaScript needs the u flag for them; lookbehind works in both. Test with the engine your code will use; this page uses JavaScript.
Why did the tester stop my pattern?
The pattern ran longer than two seconds, usually because of catastrophic backtracking: nested quantifiers such as (a+)+ try an exponential number of combinations on text that almost matches. Make the inner part more specific, avoid nested repetition, or anchor the pattern with ^ and $.
How do I use capture groups in a replacement?
Turn on Replace and refer to groups in the replacement text: $1, $2 and so on for numbered groups, $<name> for named groups and $& for the whole match. The preview shows the full result; for example ($1) $2-$3 turns 512-555-0147 into (512) 555-0147.
Automation: an MCP tool test_regex(pattern, flags, text) → matches[] and an n8n node are planned (the diff output is text).