JavaScript Regex Tester

Enter a JavaScript regular expression and test text to see matches, their positions and capture groups. Patterns that take too long are stopped in a background worker. Everything runs in your browser and your input stays on this device.

What this tool does

Run a JavaScript regular expression in a bounded worker and show matches, offsets and captured values.

What do the g, m and s flags do?

Without g you get at most one match. With g, the tool reports up to 1,000 matches per run, subject to a separate output limit. The m flag changes where line anchors match, and the s flag lets a dot match line breaks.

When to use it

Test a parser against positive and negative log lines before using it in a script that processes a larger file.

How to use it

  1. Enter the pattern without slash delimiters.
  2. Choose flags and paste a fixture with both matches and near misses.
  3. Select Test regex and inspect the groups and offsets.

Worked example

Enter the pattern Order #(?<id>\d+) and use the global flag g. Paste Order #402 and Order #1138 on separate lines as test text. Run the test to see both matches, their positions and the captured order numbers. Remove g to inspect the first match by itself. Add a line containing Order # followed by letters to make sure the pattern rejects that case. This gives you a small fixture you can keep with JavaScript code that extracts the same field from logs.

Example input
Pattern: Order #(?<id>\d+)
Flags: g
Text: Order #402
Order #1138
Example output
Captured id values: "402", "1138"

Supported features and limitations

Results use JavaScript RegExp syntax and UTF-16 positions. Each run reports up to 1,000 matches, with a separate limit on captured text. Patterns that take too long are stopped in a background worker.

Common mistakes and edge cases

Enter the pattern without slash delimiters. A backslash typed directly into the pattern field needs different escaping when it is written inside a JavaScript string literal. The m flag changes where line anchors match. The s flag allows a dot to match line breaks. Some patterns match empty strings, and large or expensive patterns can reach the display limit or worker timeout. Test a small fixture before pasting a large log. When testing a validator, include both a positive example and a near miss. If your pattern is intended to match the entire field, try extra text before and after it to confirm where your anchors apply.

Frequently asked questions

Why can a position differ from my visible character count?
JavaScript reports UTF-16 code unit offsets. Some emoji and other characters occupy two code units. Use the same indexing convention as JavaScript string slicing when mapping a result back to the original text.
Will a JavaScript match behave the same in Python?
Regex engines differ in syntax, flags and Unicode behavior. Use this tool to check JavaScript behavior and test the final pattern in the runtime that will execute it.
How do I test a named capture group?
Write the group as (?<name>...) in the pattern. The tester lists captured values by name under namedGroups in each matching result.
Why shouldn’t I type slashes around the pattern?
The pattern field takes the expression without delimiters. Enter Order #(\d+) without wrapping it in slashes.
Is there a limit on matches?
Each run reports up to 1,000 matches. Large results can hit a separate output limit first. Patterns that take too long are stopped.
Is my text uploaded anywhere?
No. It is processed in your browser and stays on your device.

Related tools

Developer guides