Re: [R] how to count the total number of (INCLUDING overl apping) occurrences of a substring within a string ?

2009-12-20 Thread Hans W Borchers
Gabor Grothendieck ggrothendieck at gmail.com writes: Use a zero lookaround expression. It will not consume its match. See ?regexp gregexpr(a(?=a), aaa, perl = TRUE) [[1]] [1] 1 2 attr(,match.length) [1] 1 1 I wonder how you would count the number of occurrences of, for example,

Re: [R] how to count the total number of (INCLUDING overl apping) occurrences of a substring within a string ?

2009-12-20 Thread Hans W Borchers
Gabor Grothendieck ggrothendieck at gmail.com writes: Try this: findall(aba, ababacababab) [1] 1 3 7 9 gregexpr(a(?=ba), ababacababab, perl = TRUE) [[1]] [1] 1 3 7 9 attr(,match.length) [1] 1 1 1 1 findall(a.a, ababacababab) [1] 1 3 5 7 9 gregexpr(a(?=.a), ababacababab, perl =