4

I have the following string:

FFDEFFDFFDCFFDDFFAAF

and the following regex pattern:

FF..FF

Running gregexpr will result in the following:

gregexpr('FF..FF','FFDEFFDFFDCFFDDFFAAF')

[[1]]
[1] 1 8
attr(,"match.length")
[1] 6 6
attr(,"useBytes")
[1] TRUE

But there is one match missing, as there are three occurrences of the pattern:

FFDEFFDFFDCFFDDFFAAF
FF..FF ||  ||  || 
       FF..FF  ||
           FF..FF

Any idea why is this happening and how to resolve this?

SwatchPuppy
  • 324
  • 1
  • 3
  • 15
  • 4
    Regex doesn't do overlapping patterns, [see here](http://stackoverflow.com/q/320448/903061) [or here](http://stackoverflow.com/q/11430863/903061) for ways to get around this with lookahead. – Gregor Thomas Jun 17 '15 at 23:23
  • Thanks, with perl=TRUE i can use lookahead as you suggested – SwatchPuppy Jun 17 '15 at 23:34

1 Answers1

3

you need a look ahead expression which you can do with a perl regex:

gregexpr("(?=FF..FF)", "FFDEFFDFFDCFFDDFFAAF", perl=TRUE)
cr1msonB1ade
  • 1,716
  • 9
  • 14