0

Seems to be an easy question, but I miss something in regex groups I guess. I have a string and I need to find how many occurrences of three patterns it has.

string="AGTGCTGGCCGATATGCNYGGAATATATGCAGTGGTGNTT"

pattern1="GGCCTATATGC"
pattern2="GGAANATATGC"
pattern3="GGCCGATATGC"

The idea is to use regular expressions.

I tried:

re.findall(r"GG[C,A]{2}[A-Z](AT){2}GC", string)

However, I do something wrong in (AT){2}, because with just writing ATAT it works. Is it somehow related to groups in regex? Would appreciate if someone can explain.

Thanks,

Hrant
  • 219
  • 3
  • 12
  • `[C,A]{2}` is wrong. Not only does it match commas, but also `AC` or `CA`. If you want to match `AA` or `CC`, the easiest way to do that is `(?:AA|CC)`. – Aran-Fey Aug 20 '18 at 16:04
  • Thanks @Aran-Fey! And thanks for pointing to the duplicate! – Hrant Aug 20 '18 at 16:07

0 Answers0