Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Pattern mattching

by monkfan (Curate)
on May 30, 2005 at 07:16 UTC ( [id://461667] : note . print w/replies, xml ) Need Help??


in reply to Pattern mattching

Hi,
$ perl -e '$str = "+000000"; $match = $str =~ /^\+\d{6}/; print "MATCH\n" if($match);'
prints:
MATCH
Regards,
Edward

Replies are listed 'Best First'.
Re^2: Pattern mattching
by Anonymous Monk on May 30, 2005 at 07:22 UTC
    It fails for $str ='+0000001';
      But you said it is fixed to "six digits". This should work, for any number of digits:
      $match = $str =~ /^\+\d+/;
      Regards,
      Edward
        What I ment to say was that it returns true even if there are more that 6 digits. I need to validate exactly six (6) digits.
      The pattern +000000 is in that string. Did you want it to match only if the whole string fits the pattern? If so then /^\+\d{6}\z/ should work.