Skip to content

JavaScript Regex Tester

Test JavaScript regular expressions against sample text and inspect matches, positions and capture groups in a worker.

Local Browser Processing Free Forever No Signup Mobile Friendly

Processing stays in this browser. Inputs are not sent to a tool-processing server or saved by this utility. Limit: 500,000 characters per input.

Learn with worked examples

How to use JavaScript Regex Tester

  1. Paste sample text in the first input and a pattern without slash delimiters in the second.
  2. Set JavaScript flags such as gi, then run the pattern.
  3. Inspect capture groups and indexes. Test both matching and non-matching examples.

A reproducible example

Use Load example to try this input, then change one value and inspect the result.

Order A-104 shipped; order B-209 pending.

Second input:
([A-Z])-([0-9]+)

Use the engine your code actually uses

This is a JavaScript RegExp tester, not a PHP PCRE or Python tester. Pattern syntax, lookbehind behavior and Unicode features can differ between engines and browser versions. Copy the pattern into the target runtime and run a regression test before relying on it.

Read captures instead of guessing

For ([A-Z])-([0-9]+), A-104 is the full match, A is capture group 1 and 104 is group 2. The report includes the start index and named capture groups when present. JavaScript indexes use UTF-16 code units, so a visible character is not always one index unit.

Flags change the result

Use i for case-insensitive matching, m to change the behavior of line anchors and s to let a dot match line terminators. The tester adds g so it can list all matches. Invalid or repeated flags are rejected by the browser engine. Unicode-mode behavior should be verified using representative input.

Bound expensive patterns

Some patterns cause excessive backtracking. Work runs in a dedicated worker that is terminated after two seconds to keep the page responsive. The report stops after 1,000 matches. A timeout is not proof that a regex is safe or unsafe for all inputs; benchmark relevant cases in the actual application.

Common questions

Should I include / around the pattern?

No. Enter the pattern only and put flags in the separate flags field.

Why does PHP give different matches?

PHP commonly uses PCRE. This tool uses JavaScript, so test the same pattern in the intended runtime.

Read the format or engine documentation. Found an edge case? Send a small reproducible example.