Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Regex Start Anchor with variables

by Samy_rio (Vicar)
on Oct 05, 2006 at 05:52 UTC ( [id://576472]=note: print w/replies, xml ) Need Help??


in reply to Regex Start Anchor with variables

Hi chrism01, use Quotemeta "\Q & \E".

if( $str1 =~ /^\Q$str2\E/ ) { print "match\n"; } else { print "nomatch\n"; }

Updated

See the documentation in perldoc as quotemeta

In string2 $str2 = ".1.2.3.4";, dots(.) are present and it will be treated as any character except new line in regular expression. So dots should be escaped using "\Q".

Regards,
Velusamy R.


eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-19 01:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found