in reply to negative lookaheads doing my 'ead in

The (?!<=) means that the stuff preceeding it mustn't be followed by '<='. Your example is, so it doesn't match. Remove either or both chars or change one or both to something else and it will match.

/ ^ # start of line \s* # optional whitespace (?!for all) # NOT "for all" (\w+) # One or more word chars \s* # optional whitespace : # a colon \s* # more optional whitespace (\w+) # another set of one or more word chars \s* # and more optional whitespace (?!<=) # NOT followed by the char sequence '<=' /i

Nah! You're thinking of Simon Templar, originally played (on UKTV) by Roger Moore and later by Ian Ogilvy

Replies are listed 'Best First'.
Re: Re: negative lookaheads doing my 'ead in
by Anonymous Monk on Nov 08, 2002 at 11:24 UTC
    right
    I just re-read my original question and of course what I meant was why does it match?

    When I run the above pattern it does match

      The reason it matches is because the immediate preceeding whitespace is optional \s*. Therefore the parser can choose to say that if there is no whitespace, then the next char after the second (\w+) is a space, which isn't '<=' so therefore is can match, so it does.

      Change that to be if (/^\s*(?!for all)(\w+)\s*:\s*(\w+)\s+(?!<=)/i) { and it no longer can match, so it doesn't (if you get my drift.

      I realise that may or may not help you.

      ++Jasper below. I couldn't find a way of doing that. The caveat is that if you wanted to match

      'cidr_enable: en_core_id == NOT(dsp_reset_n) AND <= stuff;'

      your out of luck.


      Nah! You're thinking of Simon Templar, originally played (on UKTV) by Roger Moore and later by Ian Ogilvy