Re: Function to find all matches in a string?

7 views
Skip to first unread message

Yegappan Lakshmanan

unread,
Dec 25, 2023, 1:12:17 AM12/25/23
to vim...@googlegroups.com, vim_dev
Hi Tim,

On Sat, Dec 23, 2023 at 2:35 PM Tim Chase <v...@tim.thechases.com> wrote:
I was looking for something similar to Python's re.findall()/finditer()
function to answer a question on Reddit[1] but was surprised I
couldn't find anything in

  :help function-list

The general intent would be to take an input string and return a
List containing all the sub-strings matching a pattern like

  let matches=findall('amwenxipyuqz', '[aeiou]')

would set matches to

  ['aw', 'en', 'ip', 'uq']

I was able to cobble together a hack-job in this case, but I'd hoped
to be able to do something like

  :let a=[] | g/#\w\+/call extend(a, findall(getline('.'), @/))

Does such a function exist and I just missed it?


Currently no such function exists.  I have created PR https://github.com/vim/vim/pull/13766
to add support for the matchall() function.  Can you try that out?

Thanks,
Yegappan
 
Thanks!

-tim

[1]
https://www.reddit.com/r/vim/comments/18pcd84/the_vim_way/kenedxq/


Reply all
Reply to author
Forward
0 new messages