Overlapping matches in R

前端 未结 6 1251
不思量自难忘°
不思量自难忘° 2020-12-01 18:22

I have searched and was able to find this forum discussion for achieving the effect of overlapping matches.

I also found the following SO question speaking of findin

6条回答
  •  星月不相逢
    2020-12-01 19:14

    As far as a workaround, this is what I have come up with to extract the overlapping matches.

    > x <- 'ACCACCACCAC'
    > m <- gregexpr('(?=([AC]C))', x, perl=T)
    > mapply(function(X) substr(x, X, X+1), m[[1]])
    [1] "AC" "CC" "AC" "CC" "AC" "CC" "AC"
    

    Please feel free to add or comment on a better way to perform this task.

提交回复
热议问题