1

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?

Community
  • 1
  • 1
Drew Steen
  • 16,045
  • 12
  • 62
  • 90
  • 2
    I've answered this before... let me search my answers. [Found it](http://stackoverflow.com/questions/7878992/finding-the-indexes-of-the-matching-substrings/7879329#7879329). – Joshua Ulrich Apr 11 '12 at 19:34

0 Answers0