Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^3: Using Look-ahead and Look-behind

by heyjoec (Initiate)
on Jun 19, 2014 at 11:18 UTC ( #1090445=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Using Look-ahead and Look-behind
in thread Using Look-ahead and Look-behind

I changed the sub TestEquity to allow for any text between Private and Equity, but I can't get it to work. What have I done wrong?

sub TestEquity { return 1 if $_[0] =~ m/(?<!private).*equity/; return 0; }


Comment on Re^3: Using Look-ahead and Look-behind
Download Code
Re^4: Using Look-ahead and Look-behind
by AnomalousMonk (Abbot) on Jun 19, 2014 at 12:09 UTC

    How about just (untested, and also case-sensitive):

    sub TestEquity { return $_[0] =~ m/private.*equity/ ? 0 : $_[0] =~ m/equity/ ? 1 : 0 ; }
    This could be slightly simplified if you can tolerate  "" (empty string) as a false flag in addition to or in place of 0.

    BTW: "I can't get it to work" is rarely helpful as a problem description. How about some input strings and actual versus expected output?

    Update: Changed  $_[0] =~ m/private.*equity/ to  $_[0] =~ m/private/ because it makes more sense.
    Update: ... and then changed it back to  $_[0] =~ m/private.*equity/ because it actually makes even more sense that way! (sigh)

Re^4: Using Look-ahead and Look-behind
by Anonymous Monk on Jun 19, 2014 at 23:13 UTC

    I changed the sub TestEquity to allow for any text between Private and Equity, but I can't get it to work. What have I done wrong?

    Impossible to say, although the anomalous one makes a good point

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2015-07-04 17:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls