I am trying to use qr function in Perl and also want to do case-insensitive regex matching. Below is what I am trying to do:
my $pattern = qr(Buy Qty\[([0-9]+\.?[0-9]*)\]);
my $logPattern = "BUY Qty[200000] On merchant site";
if($logPattern =~ /$pattern/i){
print "MatchFound, Qty is ==> $1";
else {
print "Match Not found";
}
However, when I run this, it gives me "Match Not found" as it is not making this regex match as case-insensitive. If I remove the qr code and use the same pattern, it gives me the correct answer.
Please let me know what I am missing here.
You have to compile regex with /i switch
my $pattern = qr(Buy Qty\[([0-9]+\.?[0-9]*)\])i;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With