Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Another RegExp question

by davis (Vicar)
on Aug 17, 2006 at 11:20 UTC ( #567888=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://567888]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2018-03-21 05:55 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (264 votes). Check out past polls.