Andy Wokula wrote:
> ... and I don't mean join().
>
> I'd like to have a function like split(), except for it should collect all
> the _matches_ in a list. "matchlist()" would be a good name for it,
> unfortunately it's already taken.
>
> How would I do it now?
A naive and inefficient but simple implementation:
function ListOfMatches(subject,pattern)
let l:matches = []
let l:matchnum = 1
let l:curmatch = matchstr(a:subject, a:pattern, 0, l:matchnum)
while l:curmatch != ""
let l:matches = add(l:matches, l:curmatch)
let l:matchnum = l:matchnum + 1
let l:curmatch = matchstr(a:subject, a:pattern, 0, l:matchnum)
endwhile
return l:matches
endfunction
E.g.
:echo ListOfMatches("abracadabra","a.")
['ab', 'ac', 'ad', 'ab']
Enjoy!
Ben.
Send instant messages to your online friends http://au.messenger.yahoo.com
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---