Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: How does this regex not match?

by targetsmart (Curate)
on Feb 13, 2010 at 14:22 UTC ( #823027=note: print w/ replies, xml ) Need Help??


in reply to How does this regex not match?

quotemeta the pattern variable and use it to match with the string
(will work for your case)

perl -ne "$var = quotemeta('my_stuff[1]=400'); print if /$var/ "


Vivek
-- 'I' am not the body, 'I' am the 'soul/consciousness', which has no beginning or no end, no attachment or no aversion, nothing to attain or lose.


Comment on Re: How does this regex not match?
Download Code
Re^2: How does this regex not match?
by AnomalousMonk (Abbot) on Feb 15, 2010 at 20:39 UTC

    I am informed by /msg from targetsmart that the example code in Re: How does this regex not match? works in Perl 5.6.1, Windows XP, to demonstrate the operation of quotemeta. I cannot see how, but I cannot test it in 5.6.1 (or even 5.8.x at the moment). It does not work in Strawberry 5.10.1.0, Windows 7.

    The following example code works to demonstrate  quotemeta in Strawberry 5.10.1.0:

    >perl -wMstrict -le "my $var = quotemeta 'my_stuff[1]'; print 'match' if 'my_stuff[1]=400' =~ /$var/; " match

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2014-12-25 17:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (161 votes), past polls