toolbench.onlineby Valkyron Labs

Developer

Regex Tester

Test a JavaScript regular expression and list every match with its index and capture groups. Flags are g, i, m, s, u, and y. Updates as you type.

Regex Tester

List JavaScript regex matches with index and capture groups.

Enter a pattern and test string.

Match results

—

Output actions

Ready to copy output once your result appears.

Live matches, indexes, and groups

Regex Tester compiles a JavaScript RegExp and lists every match from String.prototype.matchAll. The flags box keeps only g, i, m, s, u, and y. The search always includes g, even when you delete it, so the list is every non-overlapping match. Named groups are not labeled. The panel has no replace mode.

How to test a pattern

  1. 1Type the pattern without surrounding slashes. The sample placeholder is (\w+)\s(\w+). Invalid flag letters are stripped as you type, and the flags box holds at most six characters. It opens containing g.
  2. 2Paste the subject into Test string. Results recompute when the pattern, the flags, or the subject change. There is no Run button.
  3. 3Read Match results. Each line has the full match in JSON quotes, the index, and a groups list when the pattern has captures. Copy output copies that block after a match or the no-match sentence.

What it is good for

  • • Checking where a pattern matches and what each capture contains.
  • • Seeing the engine's error sentence for an unfinished group or a bad escape.
  • • Comparing a pattern here before you use it as a find pattern elsewhere.

Example

Input

Pattern (\w+)\s(\w+)
Flags g
Test string Hello World foo bar

Output

2 match(es) found:
Match 1: "Hello World" at index 0  groups: ["Hello", "World"]
Match 2: "foo bar" at index 12  groups: ["foo", "bar"]

Index 12 is the start of foo. The two spaces before groups are part of the printed line. \w does not cross the space, so the second capture stops at the end of each word.

What a result line contains

When both boxes are non-empty, the page builds a RegExp twice. The first construction uses your flags after stripping anything outside gimsuy, and it exists only to surface a syntax error. The second construction adds g if you left it out, then matchAll walks the subject. Zero matches replace the panel with No matches found. and the status repeats that sentence. One or more matches produce a count line, then one line per match: Match N, the full match passed through JSON.stringify, the word at, the index, and, when slice(1) is non-empty, groups with each capture also JSON.stringified.

Capturing parentheses appear in that groups list in source order. A non-capturing (?:...) group does not appear. A named group (?<name>...) still contributes its text to the list, but the name is not printed, because the page never reads the groups object. An optional capture that did not participate is undefined. JSON.stringify turns that undefined into an empty slot, so a hit on (a)(b)? against the letter a prints an empty slot after the comma, not the word null. The index is the start of the full match, not the start of the first group. Overlapping possibilities are not listed separately. matchAll advances past each match the way a global search does.

The six flags and the forced g

The flags field drops every character except g, i, m, s, u, and y, and it refuses a seventh character. i is case-insensitive. m changes ^ and $ so they also match at line breaks. s lets a dot match a newline. u turns on Unicode mode, which changes how escapes and astral characters are parsed. y is sticky. Duplicate letters are kept if you type them, and the RegExp constructor then throws, which you will see as a regex error rather than as a silent cleanup.

g is added for the matchAll call when the box does not already contain it. Deleting g still lists every match. The validation constructor does not receive that extra g, so a pattern that is illegal only because of a different flag still fails before the search. Sticky y combined with the added g follows whatever the engine does for those two flags together. There is no toggle that turns the global walk off.

Jobs for a match list

Use the list when you need the index and the captures, not a rewritten document. A pattern such as (\w+)\s(\w+) against Hello World foo bar reports two matches, at indexes 0 and 12, with the word pairs in the groups brackets. That is a check of the pattern, not an edit. If the next step is to substitute text, open Find & Replace. Its regex switch compiles the find box with g and an optional i. The replacement you type is inserted literally. $1 is not expanded, because the replacer returns the replacement string unchanged.

An empty pattern or an empty subject never reaches the compiler. The status stays Enter a pattern and test string. and the result panel is blank, so you cannot ask what a pattern does against a zero-length subject. A pattern that can match an empty string inside a non-empty subject still follows matchAll, which will show those empty matches when the engine produces them. Copy output after a hit copies the whole block, including the count line.

Errors, quotes, and what is not compiled

A pattern the engine rejects clears the result and sets the status to Regex error: plus the engine message. An unclosed parenthesis is the usual case. The page does not highlight the character position inside your pattern, and it does not draw match spans inside the subject. Quotes and backslashes inside a match are escaped by JSON.stringify, so a match that contains a quotation mark is printed with a backslash in front of it.

Slashes around the pattern are ordinary characters if you paste them. Do not include the /pattern/flags wrapper. Flags belong in the flags box. There is no timeout, no recursive-limit control, and no substitute box. Lookahead and lookbehind work only to the extent the JavaScript engine in your browser supports them. The page does not vendor a second regex dialect.

Rules and limitations

The dialect is JavaScript RegExp. Allowed flags are g, i, m, s, u, and y, at most six characters. matchAll always runs with g. Output lists the full match, the start index, and numbered captures. Names are omitted.

Empty pattern or empty subject produces no result. Syntax errors clear the result. There is no replace, no highlight, and no download control. Find & Replace can apply a pattern, but its replacement text is literal.

Common problems

If the panel stays empty and the status asks for a pattern and a test string, one of the two boxes is still empty. A pattern alone does not run.

If groups omit a name you wrote in (?<name>...), that is expected. The text of the capture is in the list and the name is not.

Frequently asked questions

Why do I still get every match after I delete g?

The search adds g when the flags box lacks it, then calls matchAll. The flags box can show a string without g while the list still contains every match.

Are named groups shown?

The captured text is shown in the groups list. The name from (?<name>...) is not printed. Non-capturing groups are omitted.

Can I replace matches here?

No. This page only lists matches. Find & Replace can run a pattern when its regex switch is on, and the replacement is the literal text you typed, not a $1 backreference.

What happens with an empty test string?

The search does not run. The status stays Enter a pattern and test string. and the result stays blank. Both boxes have to contain something.

Is my input uploaded or saved?

This tool processes input in your browser and does not save its input or output to local storage. Copy and download are user actions. The site uses analytics for page and action metadata and may use ads and production error reporting; see the Privacy Policy for those services.

About this tool

Maintained by Toolbench. For large or deeply nested files, split the input into smaller batches and verify representative results before using them in an import or application. Report reproducible problems through Contact.

Next steps

Related tools

Continue the workflow with nearby tools for formatting, publishing, debugging, or follow-up checks.

Trust

Policies, contact, and answers

Clear pages for how Toolbench works, what we collect, and how to reach us.