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

Re: regex matching on metacharacters

by LanX (Sage)
on Jul 21, 2022 at 00:06 UTC ( #11145617=note: print w/replies, xml ) Need Help??


in reply to regex matching on metacharacters

> But is there a more elegant way to do that, one that might also pick up some of the others?

yes, see quotemeta resp. \Q and \E

demo
>perl $v1 = "*hello"; $v2 = "*hello"; print quotemeta($v2),"\n"; print "match" if $v1 =~ /\Q$v2/; __END__ \*hello match >

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

) also perlre#Quoting-metacharacters

Replies are listed 'Best First'.
Re^2: regex matching on metacharacters
by slugger415 (Monk) on Jul 21, 2022 at 03:32 UTC

    thank you!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2022-09-25 21:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (116 votes). Check out past polls.

    Notices?