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

Hi , i am working with regular expression and got into trouble how to differentiate between two patterns

LETTER [A-Za-z] DIGIT [0-9] LABELNAME {LETTER}(_|{LETTER}|{DIGIT})*
the above rule of labelname will accept anything. now i want to have another rule
REGNAME [pP] REG_NUM [0-9]+
if i use first one i need to do further coding to get value of reg_num numerical value that why i want to use second one. problem is second rule fits in 1 rule also and so i get error results. is there any way i can have differen rules for second case and just able to have recognized patterns like p0 , P2 from second rule so that i dont need to do extra calculation to extract values as would have been in first case. Thanks

Replies are listed 'Best First'.
Re: help related to regular expression
by lidden (Curate) on Mar 04, 2010 at 07:56 UTC
    I do not know if I understand your question correctly. If you want to match a 'p' followed by some digits you can do it like this.

    my $string = 'p23'; if($string =~ /[pP](\d+)/){ print $1 }'