R
raksha34
hi all,
i have to match the following types of strings:
PTY
IN_B
IN[3]
ADD<2>
SUM{25}
MULT(9)
Here's my attempt at condensing the regular expression:
use strict;
use warnings;
my @Data = qw(
PTY
COUNT2
IN_B
IN[3]
ADD<2>
SUM{25}
MULT(9)
);
my %h = qw(
[ ]
{ }
( )
< >
);
my $pin_re = q/\A[a-zA-Z]\w*(?[<[({])\d+$h{\1})?\z/;
for my $var (@Data) {
if ($var =~ m/$pin_re/) {
print "$var match";
}
else {
print "$var NOmatch";
}
}
**************************** END of CODE **************
This is what if get:
PTY match
COUNT2 match
IN_B match
IN[3] NOmatch
ADD<2> NOmatch
SUM{25} NOmatch
MULT(9) NOmatch
****************************** END of OUTPUT **********
The reason for writing the regular expression in this format
was to avoid having to use a lot ORs.
but it doesnt work.
Can you suggest someway of fixing this?
Thanks,
Rakesh
i have to match the following types of strings:
PTY
IN_B
IN[3]
ADD<2>
SUM{25}
MULT(9)
Here's my attempt at condensing the regular expression:
use strict;
use warnings;
my @Data = qw(
PTY
COUNT2
IN_B
IN[3]
ADD<2>
SUM{25}
MULT(9)
);
my %h = qw(
[ ]
{ }
( )
< >
);
my $pin_re = q/\A[a-zA-Z]\w*(?[<[({])\d+$h{\1})?\z/;
for my $var (@Data) {
if ($var =~ m/$pin_re/) {
print "$var match";
}
else {
print "$var NOmatch";
}
}
**************************** END of CODE **************
This is what if get:
PTY match
COUNT2 match
IN_B match
IN[3] NOmatch
ADD<2> NOmatch
SUM{25} NOmatch
MULT(9) NOmatch
****************************** END of OUTPUT **********
The reason for writing the regular expression in this format
was to avoid having to use a lot ORs.
but it doesnt work.
Can you suggest someway of fixing this?
Thanks,
Rakesh