Developer Tools
Regex Tester with Live Highlighting
Type a pattern and a test string. Matches, capture groups and the replaced result update as you type.
JavaScript regular expression tester
Matches: 0 · Capture groups: 0
Replaced preview: -
Edit the pattern, flags or test text to update the matches.
This test runs entirely in your browser. Nothing is uploaded or stored on a server.
What this page does
The regex tester compiles a JavaScript regular expression and applies it to the sample text on every edit. Matches are highlighted, the count is reported, and each numbered capture group is listed so that a nested group can be read without guessing. The replace field then runs the same expression with a replacement string and shows the result.
The engine is the one built into the browser. That is a deliberate choice: whatever pattern you develop here will behave the same way in a browser script, with no translation step. It also means that patterns written for other dialects can need changes. Python's named groups, PCRE verbs and Java's possessive quantifiers are not part of the JavaScript grammar.
Reading the counts
Matches counts every non-overlapping match the engine finds. Capture groups totals the group values across those matches, which is a quick way to confirm that the group numbering matches your expectation. When a group does not participate in a match, for example because the other branch of an alternation succeeded, its value is undefined and is shown as such rather than as an empty string.
The match cap of 2000 exists because a pattern that can match an empty string will otherwise loop forever inside a global search. The tool advances the search position after an empty match and stops at the cap with a warning, so the page stays usable.
Where the tool stops
The tester does not translate dialects, does not explain a pattern in words and does not benchmark backtracking. A pattern that is fast on a sample can still be slow on a long line, so validate against realistic input before shipping it. The JavaScript test text box is also not a regex debugger: a failed compile reports the engine's error message, which is terse but accurate.
For structured text inside the sample, the JSON formatter validates the payload itself. For schedules that a pattern is meant to parse, the cron test gives a second opinion, and the keyboard test helps when the input comes from a specific keyboard layout.
Testing both directions
A pattern needs two samples: one that should match and one that should not. Most mistakes appear in the second sample, where a loose dot or a missing anchor lets the expression run past the intended boundary. Paste the non-matching text into the same box and confirm that the highlight count drops to zero.
Nested groups are easier to read in the group list than in the pattern. Add one pair of parentheses at a time and watch how the numbering shifts, because inserting a group renumbers every group to its right. A replacement that used $1 before the edit may need $2 after it.
Flags belong to the test as much as to the pattern. Turning on the case-insensitive flag can make a previously valid failure disappear, and the global flag changes a single match into a list. Record the flags with any pattern you plan to reuse, or the same expression will behave differently next time.
How to use this test
-
Enter a pattern
Type the expression into the Regular expression field, without slashes.
-
Choose flags
Tick g, i, m, s or u under Regular expression flags to change how the engine reads the pattern.
-
Paste sample text
Put a representative sample into Test text; every match is highlighted as you type.
-
Inspect capture groups
The list below the counts shows the value of each numbered group for every match.
-
Try a replacement
Type a replacement such as $1 into Replace with and read the result in the replaced preview.
How to read the numbers
| Signal | Typical reading | How to read it |
|---|---|---|
| Matches | Count | Every match in the test text is counted, up to 2000. |
| Capture groups | Values per match | Undefined groups mean the branch did not participate. |
| Flags | g, i, m, s, u | Global finds every match; the others change case, line, dot and Unicode behaviour. |
| Replace | Preview text | Uses JavaScript replacement syntax such as $1 for a group. |
Browser support
| Browser | Support | Notes |
|---|---|---|
| Chrome and Edge | Supported | JavaScript regular expression engine. |
| Firefox | Supported | JavaScript regular expression engine. |
| Safari | Supported | Lookbehind is supported from Safari 16.4. |
| Mobile browsers | Supported | Entering long patterns is easier with a keyboard. |
Tips
- Test against text that does not match as well as text that does; both directions catch mistakes.
- Prefer a character class over a dot when the input can contain line breaks.
- When a pattern looks right but fails, check whether the g flag from the previous edit is still on.
Frequently asked questions
Which regular expression syntax is supported?
The JavaScript engine of your browser, with the g, i, m, s and u flags and Unicode property escapes where the engine supports them. Lookbehind needs a recent browser.
Why did only the first match highlight?
The g flag is off. Without it the engine returns a single match and stops.
What happens when the pattern matches an empty string?
The tool stops after 2000 matches to keep the tab responsive. A pattern that can match nothing usually needs a more specific anchor.
Is the replace preview the same as JavaScript replace?
Yes. It uses JavaScript replacement syntax, including $1 for groups, $& for the whole match and $$ for a literal dollar sign.