Regex * Matches Empty String – Use + When One Is Required

Local only

Fix a valid regex that unexpectedly returns Match because the * quantifier is allowed to consume zero occurrences.

3 chars · 1 line

8 chars · 1 line

Pattern did not match the inputFlags: g

Regex quantifier behavior

Why regex * can match an empty string

The pattern \d* is valid and means zero or more digits. On abc, JavaScript can satisfy it with zero digits at the start, so test() returns Match even though the input contains no digit. This tool is free to use. No account or payment is required.

Last updated

What you can do here

  • Valid regex behavior check
  • Zero-length match example
  • Star-versus-plus comparison
  • Match or No match output
  • JavaScript RegExp semantics
  • Browser-local processing

Steps

  1. Identify the token followed by * and ask whether zero occurrences are acceptable.
  2. Change * to + when at least one occurrence must be present.
  3. Retest an input with zero, one, and several occurrences to verify the minimum count.

* means zero or more, while + means one or more

A successful zero-length match is still a match. This matters in validation and scanning patterns where an apparently specific token can become optional because of *.

Star-versus-plus regex example

Require at least one digit instead of allowing zero digits.

Zero-or-more pattern

\d*

One-or-more pattern

\d+

Common questions

Frequently asked questions

Why does \d* match abc?

Because * allows zero digits, and a zero-length match satisfies the regex.

Would \d+ match abc?

No. + requires at least one digit.

Can zero-length matches cause scanning issues?

They can if a manual exec loop never advances. VetaTool's Match All scanner explicitly advances after empty matches.

Debugging a specific Regex issue? Browse Regex troubleshooting.