vim-maktaba icon indicating copy to clipboard operation
vim-maktaba copied to clipboard

Regex utility function for returning all regex matches

Open dbarnett opened this issue 10 years ago • 0 comments

If you want to perform a regex search in a string as with match(), there doesn't seem to be any way to get all matches at once except for awkwardly looping through count values and repeatedly calling match().

We should create a utility function that will take a regex and return all matches, similar to python's re.findall. Each match will have a few properties you might want to know (start, end, capture groups), so it makes sense to return a dict for each, something like:

echo maktaba#re#FindAll('foobarbaz', '[aeiou]\+')

[{'start': 1, 'end': 2, 'groups': []}, {'start': 4, 'end': 4, 'groups': []}, {'start': 7, 'end': 7, 'groups': []}]

dbarnett avatar Mar 23 '15 04:03 dbarnett