Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

qr function does not match case-insensitively

Tags:

regex

perl

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.

like image 317
ANewDeveloper Avatar asked Apr 20 '26 06:04

ANewDeveloper


1 Answers

You have to compile regex with /i switch

my $pattern = qr(Buy Qty\[([0-9]+\.?[0-9]*)\])i;
like image 187
mpapec Avatar answered Apr 21 '26 19:04

mpapec



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!