Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Regex with variables

by AnomalousMonk (Bishop)
on Jun 30, 2015 at 01:44 UTC ( #1132548=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1132548]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (1)
As of 2021-10-21 02:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (82 votes). Check out past polls.

    Notices?