0

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 :)

Mat
  • 202,337
  • 40
  • 393
  • 406
Max_IT
  • 602
  • 5
  • 15

0 Answers0