Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Having a problem with negative look behind assertion

by jethro (Monsignor)
on Feb 12, 2013 at 14:08 UTC ( #1018371=note: print w/ replies, xml ) Need Help??


in reply to Having a problem with negative look behind assertion

I would say only Athanasius has a correct answer yet, I see mistakes in the other answers. So I made sure and tested. This should work (and still uses only one regex):

if( $line =~ /^(?!fee).*[Bb]ar.*\.java/ )

This is a negative look-ahead fixed at the start of the line (with ^).


Comment on Re: Having a problem with negative look behind assertion
Download Code
Replies are listed 'Best First'.
Re^2: Having a problem with negative look behind assertion
by SirClive (Scribe) on Feb 12, 2013 at 14:25 UTC
    I wanted a single regexp if possible and this looks like it does the trick. Many thanks for the replies !
Re^2: Having a problem with negative look behind assertion
by Anonymous Monk on Feb 12, 2013 at 14:14 UTC

    I would say only Athanasius has a correct answer yet, I see mistakes in the other answers.

    obviously wrong

      If you mean to say your fourth answer is correct I beg to differ. !/fee/ aborts for "fee" anywhere in the string instead of only at the start like the OP wanted

      UPDATE:

      If you mean to say your third answer is correct I beg to differ. It expects a '/' after "fee". While this is always the case in the examples it is not what the OP said (although there is a chance that the OP misstated the problem)

        Gee, you say ^ is critical, is there an answer with ^, I wonder

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2015-07-31 02:21 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 (274 votes), past polls