Regex Test Cases Runner (Should Match / Should Not Match)

Checks one JavaScript regex against many test strings. Mark each line as must match or must not match and see which ones pass.

Use the tool

Why this tool exists

A regex that works on the three examples you tried can still accept bad input or reject good input. A list of positive and negative cases catches both kinds of mistake and gives you a small regression test to keep with the pattern.

Put "+ " before a string that should match and "- " before one that should not. The tool runs them all and prints PASS or FAIL per line with a count. You can match anywhere in the string or require the whole string to match, which is what most validation patterns need.

How to use it

  1. Enter the regex in the first box.
  2. Write test cases in the second box, one per line, starting with "+ " or "- ".
  3. Choose anywhere or whole string matching.
  4. Fix the pattern until every line shows PASS.

Frequently asked questions

Why do lines need a + or - prefix?

The prefix says what you expect. Lines without a prefix are ignored, so you can leave comments or blank lines in the list.

What is the difference between the match modes?

Anywhere means the pattern may match a part of the string. Whole string wraps the pattern in ^(?:...)$ so all of it must match.

Does it support other regex engines?

No. It runs the JavaScript engine. Behaviour can differ in PCRE, Python and Java.

Can a pattern hang the page?

A pattern with catastrophic backtracking can. Run it through the ReDoS checker first if you are unsure.