Search notes:

VIM regular expressions: Non greedy matches

A * matches with greed (that is: as much as possible).
To match as little as necessary, use \{-} (or with magic: {-})
" ../vimscript/run_ non_greedy

redir > non_greedy.out

let s:text = 'The #foo# and the #bar# and the #baz# and others, too'

" greedy matching

let  s:greedy_match = matchstr(s:text, '#.*#')
echo s:greedy_match
"
"  #foo# and the #bar# and the #baz#
"

let  s:non_greedy_match = matchstr(s:text, '#.\{-}#')
echo s:non_greedy_match
"
"  #foo#
"

let  s:non_greedy_match_magic = matchstr(s:text, '\v#.{-}#')
echo s:non_greedy_match_magic
"
"  #foo#
"

redir END
q
Github repository about-vim, path: /regular_expressions/non_greedy.vim

See also

regular expressions
VIM script

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