google / google/vim-maktaba

Regex utility function for returning all regex matches

Open
#138 0 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
Vim Script
Stars
588
Forks
41
PR merge metrics
No merged PRs in 30d

Description

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:

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

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.