Given the following text:
My name is foo.
My name is bar.
With the goal being to return each line which contains or does not contain a particular substring, both of the following positive and negative regex patterns can be used to return the same result:
Postive lookahead: ^(?=.*bar).*$
returns My name is bar.
Negative lookahead: ^((?!foo).)*$
returns My name is bar.
However, why does the negative lookahead need to be nested within multiple sets of parentheses with the qualifier .
and the quantifier *
separated by the parentheses whereas in the positive lookahead, they can be adjacent .*
?