I have the following string:
seq = 'MNRYLNRQRLYNMYRNKYRGVMEPMSRMTMDFQGRYMDSQGRMVDPRYYDHYGRMHDYDRYYGRSMFNQGHSMDSQRYGGWMDNPERYMDMSGYQMDMQGRWMDAQGRYNNPFSQMWHSRQGH'
also saved in a file called seq.dat. If I use the following grep command
grep '\([MF]D.\{4,6\}\)\{3,10\}' seq.dat
I get the following matching string:
MDNPERYMDMSGYQMDMQGRWMDAQGRYN
which is what I want. In words, what I want to match is as many consecutive repeats as the string has of [MF]D.{4,6}. I don't want to match cases where it has less than 3 consecutive repeats, but I want it to be able to capture up to 6.
Now, I'm trying to do this with python. I have
p = re.compile("(?:[MF]D.{4,6}){3,10}")
Trying search() returns
MDNPERYMDMSGYQMDMQGRWM
It is the close to the answer I seek, but is still missing the last MDAQGRYN. I'm guessing this is because .{4,6} matches the M, which in turn prevents {3,10} from capturing this 4th occurence of ([MF]D.{4,6}), but since I asked for at least 3, it's happy and it stops.
How do I make Python regex behave like grep does?