Possible Duplicate:
Finding the indexes of multiple/overlapping matching substrings
I have a character vector that looks like this
s <- c("aab", "aabaa", "aabaaa")
I want to search for all the occurrences of "aa" including overlapping occurrences, such that s[2] would have two occurrences (starting at position 1 and 4) and s[3] would have 3 occurrences (starting at positions 1, 4, and 5). That would look something like:
functionImLookingFor("aa", s)
> [[1]]
> [1] 1
>
> [[2]]
> [1] 1
> [2] 4
>
> [[3]]
> [1] 1
> [2] 4
> [3] 5
I'm new to using regular expressions, but none of the functions that I've found seem to be able to handle overlapping occurrences of patterns. What am I missing?