... use quotemeta ...
... or \Q$string\E its interpolative equivalent:
c:\@Work\Perl\monks>perl -wMstrict -le "my @inputData = qw(test.dat test.exe testadat.exe testaexe.dat); ;; my @search_strings = qw(test.dat test.exe); ;; print '----- With quotemeta ------------------'; foreach my $search (@search_strings) { print qq{Using search string '\Q$search\E':}; foreach my $inputLine (@inputData) { if ($inputLine =~ m{ \Q$search\E }xms) { print qq{ Matched: '$inputLine'}; } } } " ----- With quotemeta ------------------ Using search string 'test\.dat': Matched: 'test.dat' Using search string 'test\.exe': Matched: 'test.exe'
Give a man a fish: <%-(-(-(-<
In reply to Re^2: Regex with variables
by AnomalousMonk
in thread Regex with variables
by cormanaz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |