Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: matching the + character

by suaveant (Parson)
on Aug 06, 2001 at 21:43 UTC ( [id://102521]=note: print w/replies, xml ) Need Help??


in reply to matching the + character

+ is a special character in regular expressions that means match one or more of what is before me... your regexp will match one or more a's followed by a b... i.e. aaab ab aaaaaab, to match a plus you must escape it, using a \ so \+ will match a plus... see perlre

Update Doh, my eyes skipped the lower text... :)

you need the \\ because "" interploates data, thus converting \+ to + before it gets to the regexp... if you use single quotes 'a\+b' then you will be ok.

                - Ant
                - Some of my best work - Fish Dinner

Replies are listed 'Best First'.
Re: Re: matching the + character
by Anonymous Monk on Aug 06, 2001 at 22:10 UTC
    use strict; 3 my $var1 = "a+b"; 4 my $var2 = "a+b"; 5 if ($var1 =~ /\Q$var2\E/) { 6 print "hey it matches \n"; 7 } 8 9 print "hey here \n"; 10
    See Line : 5
Re: Re: matching the + character
by jalebie (Acolyte) on Aug 06, 2001 at 21:48 UTC
    I know that thats i even tried matching by setting
    use strict; my $var1 = "a+b"; my $var2 = "a\+b"; if ($var1 =~ /$var2/) { print "hey it matches \n"; } print "hey here \n";
    but it doesn't work. AGAIN the only thing that works is
    $var2 = "a\\+b";
    please explain Waris

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-16 07:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found