Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Answer: How do I escape special characters like . / or in a regular expression?

( #108735=categorized answer: print w/ replies, xml ) Need Help??

Q&A > regular expressions > How do I escape special characters like . / or | in a regular expression? contributed by Codmate

It is possible to use another character (other than "/") to make a regex. A hash symbol can be used for example:
$changeme = "/this/url/would/be/a/nightmare/in/regex/"; $changeme =~ s#would/be#is/not#;
You can also escape all special characters in a regex with "\Q" and "\E" like this:
$changeme = "/this/url/wo*ld/b^e/a/nightmare/in/regex/"; $changeme =~ s/\Qwo*ld/b^e\E/\Qis/not\E/;

Comment on Answer: How do I escape special characters like . / or in a regular expression?
Select or Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2014-09-18 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (127 votes), past polls