Tony Mechelynck schrieb:
> 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?
>>
>
> " untested
> " note: name, if not script-local, must start with an uppercase letter
> function Matchlist(string,pattern)
> let res = '['
> let s = a:string
> let p = '\(' . a:pattern . '\).*'
> while match(s,a:pattern) != -1
> let res .= substitute (s,p,submatch(1)) . ','
> let s = substitute(s,a:pattern,'')
> endwhile
> if res == '['
> return []
> else
> let res = substitute(res,'.$',']')
> return eval(res)
> endif
> endf
>
> Best regards,
> Tony.
Thanks for the input, but I didn't get your function to work :-(
Ok, for now I'll go with this:
func! SplitMatch(str, pat)
let matpos = match(a:str, a:pat)
let reslist = []
let mendp = 0 " match (after) end position
while matpos >= 0
let mendp = matchend(a:str, a:pat, mendp)
call add(reslist, strpart(a:str, matpos, mendp-matpos))
let matpos = match(a:str, a:pat, mendp)
endwhile
return reslist
endfunc
--
Andy
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---