Search notes:

VIM regular expressions: negative lookahead

" ..\vimscript\run_.bat negative_lookahead
"
" A negative lookahead assertion is built with
"
"   ATOM\@! 
"
" or, if using \v, with
"
"   ATOM@!
"

fu! Match_two_not_followed_by_three(text) " {

  let l:matched = match(a:text, '\vtwo(.*three)@!')

  if l:matched == -1
     echo a:text . "  doesn't match a 'two' not followed by a 'three'"
  else
     echo a:text . "  matches       a 'two' not followed by a 'three'"
  endif

endfu " }

redir > negative_lookahead.out

call Match_two_not_followed_by_three('some numbers: one, two, three, four, five')
call Match_two_not_followed_by_three('odd numbers: one, three, five, seven     ')
call Match_two_not_followed_by_three('even numbers: two, four, six, eight      ')


redir END
q

" some numbers: one, two, three, four, five  doesn't match a 'two' not followed by a 'three'
" odd numbers: one, three, five, seven       doesn't match a 'two' not followed by a 'three'
" even numbers: two, four, six, eight        matches       a 'two' not followed by a 'three'
Github repository about-vim, path: /regular_expressions/negative_lookahead.vim

See also

regular expressions
VIM script
Perl: negative lookahead

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...', 1758198715, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/vim/script/regular_expressions/negative_lookahead(79): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78