Vim Regex : How to search for A AND B NOT C -
i have many lines containing names of presidents carter, bush, clinton, obama. contain 1 of names, 2, 3, 4 of them (in order).
i know how search carter , clinton , obama ->
:g/.*carter\&.*clinton\&.*obama/p i know how search carter , (clinton or bush) ->
:g/.*carter\&\(.*clinton\|.*bush\)/p (there better ways that)
but can't figure how search (and looked @ related questions), e.g., bush , clinton not carter , less how search, e.g., bush , clinton not (carter or obama).
to represent not, use negative assertion \@!.
for example, "not bush" be:
^\(.*bush\)\@! or using \v:
\v^(.*bush)@! important: note leading ^. while it's optional if use positive assertions (one match other), required anchor negative assertions (otherwise can still match @ end of line).
translating "bush , clinton , not (carter or obama)":
\v^(.*bush)&(.*clinton)&(.*carter|.*obama)@! addendum
to explain relationship between \& , \@=:
one&two&three is interchangeable with:
(one)@=(two)@=three the difference \& directly mirrors \| (which should more obvious , natural), while \@= mirrors perl's (?=pattern).
Comments
Post a Comment