I\'d like to use a variable as a RegEx pattern for matching filenames:
my $file = \"test~\";
my $regex1 = \'^.+\\Q~\\E$\';
my $regex2 = \'^.+\\\\Q~\\\\E$\';
prin
As documentation says:
$re = qr/$pattern/;
$string =~ /foo${re}bar/; # can be interpolated in other patterns
$string =~ $re; # or used standalone
$string =~ /$re/; # or this way
So, use the qr
quote-like operator.
You cannot use \Q
in a single-quoted / non-interpolated string. It must be seen by the lexer.
Anyway, tilde isn’t a meta-character.
Add use regex "debug"
and you will see what is actually happening.