I am using regular expression using scalars here. First time though. I will put the code. It should be self evident
#!/usr/bin/perl
my $regex = "PM*C";
my $var = "PM_MY_CALC";
if($var =~ m/$regex/){
print "match \n";
}
else{
print "no match\n";
}
if($var =~ $regex ){
am i missing something obvious here?
You're missing how regular expressions work. They don't work how shell filename expansion works.
Your regex uses *
which means "zero of more of the preceding character". So M*
matches nothing, 'M', 'MM', 'MMM', etc.
You wanted to match "PM" followed by any number of any character followed by "C". The correct regex for that is PM.*C
. A dot (.
) means "match (almost) any character" and (as I said above) *
matches zero or more of that.
I recommend reading the Perl Regular Expression tutorial.