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?
            Asked
            
        
        
            Active
            
        
            Viewed 98 times
        
    1 Answers
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.
 
     
    