How do you find all matches in regexes with C?

c, posix, regex

Solution

Assuming you're using POSIX `regcomp`/`regexec`, each call to `regexec` will only find the first match in the string. To find the next, use the end position of the first match (the 0th entry of the `regmatch_t` array filled by `regexec`) as an offset to apply to the string before searching it again. Repeat until you have no more matches. You can write a function to do this if you want.

Problem

Is there a findall function in C's regex library like there is in python: ``` re.findall(pattern, input_string) ``` I have a string containing filenames like so: `"path/to/file1.ics,path/file2.ics"` with an undetermined number of files in the string. I want to find all the filenames (including their path) and put them in an array of strings. I'm using the GNU `regex.h` library

Original source