Search notes:

vim script: matchlist

" ..\run_ matchlist

redir > matchlist.out

fu! M(pattern, txt) " {

 let l:ml = matchlist(a:txt, a:pattern)

 echo '  len (l:ml): ' . len(l:ml)

 for i in range(0, len(l:ml)-1)
   echo '    ' . i . ': ' . l:ml[i]
 endfor

 echo ''


endfu " }

call M ('\vfoo(\d+)bar(\d+)baz', 'foobarbaz')
"   len (l:ml): 0

call M ('\vfoo(\d+)bar(\d+)baz', 'foo42bar17baz')
"   len (l:ml): 10
"     0: foo42bar17baz
"     1: 42
"     2: 17
"     3: 
"     4: 
"     5: 
"     6: 
"     7: 
"     8: 
"     9: 
"

call M('\v(\d+)?(\S+)', '20abc')
"   len (l:ml): 10
"     0: 20abc
"     1: 20
"     2: abc
"     3: 
"     4: 
"     5: 
"     6: 
"     7: 
"     8: 
"     9: 

call M('\v(\d+)?(\S+)', 'def20')
"  len (l:ml): 10
"    0: def20
"    1: 
"    2: def20
"    3: 
"    4: 
"    5: 
"    6: 
"    7: 
"    8: 
"    9: 

call M('\v((\d+)?(\D+)?)', '42xyz')
"  len (l:ml): 10
"    0: 42xyz
"    1: 42xyz
"    2: 42
"    3: xyz
"    4: 
"    5: 
"    6: 
"    7: 
"    8: 
"    9: 


redir END
q
Github repository about-vim, path: /vimscript/functions/matchlist.vim

See also

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