in reply to Regex {3} matches 3 or more?

> I thought {3} should match only 3, not more or less.

Yes, but in your case anywhere.

If you want to only match strings with exactly three digits you need anchors for start and end of string.

/^[0-9]{3}$/

See perlreref#ANCHORS

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: Regex {3} matches 3 or more?
by pritesh_ugrankar (Monk) on Sep 05, 2020 at 14:07 UTC

    Hi Rolf,

    Thank you for the clarity.