Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to create an if statement that can only display out put if it is the letter v followed by 2 numbers (i.e. v14)OR just 2 numbers (i.e. 14). My current statement looks like this:
if ($variable =~ /v\d{2}|\d{2}/) { print "$variable"; } else { print "it is not in the proper form"; }
Can anybody help?

Edit: Added <code> tags. larsen

Replies are listed 'Best First'.
Re: HELP! - Pattern matching problem
by DamnDirtyApe (Curate) on Jul 24, 2002 at 17:52 UTC
Re: HELP! - Pattern matching problem
by mephit (Scribe) on Jul 25, 2002 at 04:17 UTC
    /^(v\d{2}|\d{2})$/ works, in addition to what DamnDirtyApe said here. (Parens are your friends when using alternations in a regex.)

    --

    There are 10 kinds of people -- those that understand binary, and those that don't.