I'm finding that when I combine ^
with \Q \E
in Perl regex, I no longer get matches that I should be getting:
$names = "20170101--NAME1-NAME2";
@list = ( '20170101--NAME1-NAME2-bt123456789.xml',
'20170101--NAME1-NAME2-bt234567890.xml');
@numbers = ( '123456789', '234567890' );
for my $filename (@list) {
if ($filename =~ /\Q$names\E-bt[^\Q$numbers[0]\E]\.xml/) {
print "$filename\n";
}
}
This gives 0 matches, but should match '20170101--NAME1-NAME2-bt234567890.xml'
. If I change the regex in the if statement to:
/\Q$names\E-bt(\Q$numbers[0]\E)\.xml/
This returns:
'20170101--NAME1-NAME2-bt123456789.xml'
I know it's not matching the same thing as my original regex, just proving that the regex works without the ^
. I also tried the following just in case:
^[\Q$numbers[0]\E] # 0 matches
(^\Q$numbers[0]\E) # 0 matches