JavaScript Regex Tester

Test a JavaScript regular expression against sample text and inspect match positions and capture groups.

Runs in your browser. 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.

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.

Related tools

Developer guides