Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: regexp w/ special chars

by shenme (Priest)
on Aug 27, 2003 at 19:59 UTC ( #287151=note: print w/replies, xml ) Need Help??


in reply to regexp w/ special chars

Use \Q and \E to 'quote' the string being interpolated into the search:
$string =~ s/\Q$token\E/$date/;
Otherwise you get a nasty message:
Invalid [] range "Y-%" in regex; marked by <-- HERE in m/[DATE:%Y-% <-- HERE m-%d]/

Or you could use quotemeta() on the string beforehand?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2021-06-25 07:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (134 votes). Check out past polls.

    Notices?