I am trying to use regexpr in R to find overlapping matches; following the elegant solution posted here: Finding the indexes of multiple/overlapping matching substrings , I am trying to use a variable as pattern:
myString<- 'abccdccdca'
myPattern<- 'ccdc'
#This Works
gregexpr(pattern = "(?=ccdc)", text = myString, ignore.case = TRUE)
#This DOES NOT Work:
gregexpr(pattern = "(?=myPattern)", text = myString, ignore.case = TRUE)
The latter reads myPattern
as a string. I have done some search, using perl $
and {}
operators, but I don't seem to be able to make it work. I would be grateful for any help :)