http://qs321.pair.com?node_id=1132548


in reply to Re: Regex with variables
in thread Regex with variables

... 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:  <%-(-(-(-<