Sunday, December 24, 2023

Re: Function to find all matches in a string?

Hi Tim,

On Sat, Dec 23, 2023 at 2:35 PM Tim Chase <vim@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/


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAAW7x7mvoU%3DkxhBPbdPAnATW9vNgJ3ZXYD9YoJzv4jbwvdcw8g%40mail.gmail.com.

No comments:

Post a Comment