in reply to Negative Lookahead Assertion Problem

Let's say you are trying to match /\w+::\w+(?!\s*\()/ against 'Foo::Bar ('. Initially the \w+::\w+ will match "Foo::Bar"; then it notices that the assertion fails (because what follows is " ("), so it will backtrack to Foo::Ba, where it will try the assertion again, and it will succeed (because "r (" isn't matched by \s*( ).

To get what you want, you could try to ensure that you reached the end of the word, with something like /\w+::\w+\b(?!\s*\()/ .

Replies are listed 'Best First'.
Re^2: Negative Lookahead Assertion Problem
by Anonymous Monk on Jul 18, 2005 at 23:34 UTC
    /\w+::(?>\w+)(?!\s*\()/ might be better for the person that has to read your code later