Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Pattern mattching

by Anonymous Monk
on May 30, 2005 at 07:22 UTC ( [id://461677] : note . print w/replies, xml ) Need Help??


in reply to Re: Pattern mattching
in thread Pattern mattching

It fails for $str ='+0000001';

Replies are listed 'Best First'.
Re^3: Pattern mattching
by monkfan (Curate) on May 30, 2005 at 07:25 UTC
    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.
        Then you need another anchor.
        /^\+\d{6}$/


        holli, /regexed monk/
Re^3: Pattern mattching
by tilly (Archbishop) on May 30, 2005 at 07:31 UTC
    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.