Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
more useful options
 
PerlMonks  

Re: Regex: Searching for a string with special characters

by liverpole (Monsignor)
on Nov 02, 2006 at 18:28 UTC ( [id://581981]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Regex: Searching for a string with special characters

I assume by 'brackets' you mean parentheses? That is, '(' and ')'?

Try using \Q ... \E in your regular expression if you want to 'escape' the string being searched against:

if ( ! /\Q$search\E/ ) { print "No Match found\n"; next; }

You can find more by reading perlre.

And another option is to use the qr/\Q$search\E/ syntax, which you can find in perlop.

Update:  Fixed wording (thanks for pointing that out, Hofmator++.)

Good luck!


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Replies are listed 'Best First'.
Re^2: Regex: Searching for a string with special characters
by Hofmator (Curate) on Nov 03, 2006 at 05:26 UTC
    And another option is to use the qr/$string/ syntax, which you can find in perlop.

    Just a small annotation. This is only correct if it is supposed to be a general comment. The qr/$string/ construct has no influence on the escape issue whatsoever.

    For the escaping see also quotemeta.

    -- Hofmator

    Code written by Hofmator and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      Thanks a lot.

      As mentioned by you, 'qr' didn't work for me but I was able to get the desired results using 'quotemeta'.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://581981]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.