Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^3: Regex help

by ccn (Vicar)
on May 06, 2009 at 11:31 UTC ( #762230=note: print w/replies, xml ) Need Help??

in reply to Re^2: Regex help
in thread Regex help

What is the reason to put \E at the end of a regexp?

Replies are listed 'Best First'.
Re^4: Regex help
by moritz (Cardinal) on May 06, 2009 at 11:53 UTC
    It doesn't make a difference, but if you want to write something after the variable, it's treated literally unless there's an \E. That's a common mistake I made, so I always haven an \E for every \Q.


    $ perl -Mre=debug -e 'my $x= "*"; /\Q$x.+/' Compiling REx "\*\.\+" Final program: 1: EXACT <*.+> (3) 3: END (0) anchored "*.+" at 0 (checking anchored isall) minlen 3 Freeing REx: "\*\.\+"
    You see that the .+ is also treated literally.
Re^4: Regex help
by ikegami (Pope) on May 06, 2009 at 15:21 UTC
    It's easier to say

    Use /\Q$variable\E/


    Use /\Q$variable/ except if that's not the entire regexp pattern. You probably have to use /\Q$variable\E/ then.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2021-10-26 15:57 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (90 votes). Check out past polls.