Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Answer: How do I escape metacharacters in a user-defined string?

by Perlmage (Acolyte)
on Jul 11, 2000 at 10:11 UTC ( #21919=categorized answer: print w/replies, xml ) Need Help??

Q&A > regular expressions > How do I escape metacharacters in a user-defined string? - Answer contributed by Perlmage

You could also use quotemeta(), which is how the \Q is implemented. Ie.,

$formula = '(4+5)';
$bit = quotemeta $formula;
if ( $formula =~ /$bit/ ) {
  print "yeah\n"; 
} else { 
  print "Oh no!\n"; 
}
This will handle literal '$' and '@'.

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[prospect]: Hello, did anyone archived the video lessons from Randall L. Schwartz ? They where on youtube a few weeks aga but O'reilly Media took them down =(

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2017-09-25 10:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (279 votes). Check out past polls.

    Notices?