Search notes:

VIM regular expressions: negative lookbehind

" ..\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'
Github repository about-vim, path: /regular_expressions/negative_lookbehind.vim

See also

regular expressions
VIM script
Perl's negative lookbehind regular expression

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758198755, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/vim/script/regular_expressions/negative_lookbehind(79): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78