tags:

views:

310

answers:

1

Is it possible to count how many times a substring appears in a string using regex matching with GNU libc regexec()?

+1  A: 

No, regexec() only finds one match per call. If you want to find the next match, you have to call it again further along the string.

If you only want to search for plain substrings, you are much better off using the standard C string.h function strstr(); then you won't have to worry about escaping special regex characters.

bobince