[TriLUG] Negative search in Vi

Kevin Hunter hunteke at earlham.edu
Sat Apr 12 18:58:25 EDT 2008


Craig Taylor wrote:
> Negate your regular expression search, eg: for lines that don't have 'dog'
> use :
> 
> /^.*[^d][^o][^g].*$

Hrm, I think this would match pretty much anything but strings less than 
(in this case 6) characters:

'bog'      no match
'doga'     match    'dog' doesn't match, but 'oga' does
'dagger'   match    d and g don't match, but second 'ger' does

Is Scott perhaps looking for negative lookaround assertions?  This is 
something I definitely wouldn't mind knowing how to do in vi, but have 
yet to figure out how.  At this point, I tend to write a few test cases 
in a file and run it through Perl, where I know how to do negative and 
positive lookaheads and lookbehinds:

m/^.someregex(?!Don'tBeAtEndOfString$)/

Kevin



More information about the TriLUG mailing list