1

i would like to match the sequence (G{x})([ACGT]{1,7})(G{x})([ACGT]{1,7})(G{x})([ACGT]{1,7})(G{x}) where x is a number between 2 and 5, which can vary between matches but must be the same between groups inside a single match. Is it possible to do this with a single regex?

mtp
  • 35
  • 4

1 Answers1

3

You can use backreferencing:

(G{2,5})([ACGT]{1,7})\1([ACGT]{1,7})\1([ACGT]{1,7})\1

Working example: https://regex101.com/r/yL5tE6/1

Note that it does allow more Gs than there were on the first group, because [ACGT] might add Gs in adjacent to \1.

Community
  • 1
  • 1
Kobi
  • 135,331
  • 41
  • 252
  • 292