in reply to Another RegExp question

The regex /\d{3}/ matches 3 digits anywhere in the string. If you want to restrict it to only 3 digits, you'd need to anchor it (specify either (both in this case) "start of the string" and the "end of the string" — these are logical atomic units):
if ($step =~ /^\d{3}$/) {

Update: YAPE::Regex::Explain gives the following explanation:

The regular expression: (?-imsx:^\d{3}$) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- ^ the beginning of the string ---------------------------------------------------------------------- \d{3} digits (0-9) (3 times) ---------------------------------------------------------------------- $ before an optional \n, and the end of the string ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------

Kids, you tried your hardest, and you failed miserably. The lesson is: Never try.
Edited: Fixed slightly mixed tense.

Replies are listed 'Best First'.
Re^2: Another RegExp question
by Ronnie (Scribe) on Aug 17, 2006 at 11:32 UTC
    Thanks for that - guess who's feeling a tad foolish at the moment?!
      Don't - it is a common mistake.