-
Notifications
You must be signed in to change notification settings - Fork 1
/
negative_lookbehind.vim
36 lines (28 loc) · 1 KB
/
negative_lookbehind.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
" ..\vimscript\run_.bat negative_lookbehind
"
" A negative lookbehind assertion is built with
"
" ATOM\@<!
"
" or, if using \v, with
"
" ATOM@<!
fu! Match_baz_not_preceeded_by_foo(text) " {
let l:matched = match(a:text, '\v(foo.*)@<!baz')
if l:matched == -1
echo a:text . " doesn't match a 'baz' not preceeded by a 'foo'"
else
echo a:text . " matches a 'baz' not preceeded by a 'foo'"
endif
endfu " }
redir > negative_lookbehind.out
call Match_baz_not_preceeded_by_foo('a foo, a bar and a baz went to a theatre')
call Match_baz_not_preceeded_by_foo('a qux, a bar and a baz went to a theatre')
call Match_baz_not_preceeded_by_foo('baz')
call Match_baz_not_preceeded_by_foo('foobaz')
redir END
q
" a foo, a bar and a baz went to a theatre doesn't match a 'baz' not preceeded by a 'foo'
" a qux, a bar and a baz went to a theatre matches a 'baz' not preceeded by a 'foo'
" baz matches a 'baz' not preceeded by a 'foo'
" foobaz doesn't match a 'baz' not preceeded by a 'foo'