How about this:
Test string:
tagaga
Regex:
(?=(aga)).{2}(?<=.)(\1)
Matches:
"aga", "aga"
Working regex example:
However depending on the length if the match, ie. in your example aga
length is 3, so you would have to modify the quantifier to the length -1. (in this case {2}
). So.. If your match was abca
you would have to change the quantifier to {3}
.
So with test example:
abcabca
Regex:
(?=(abca)).{3}(?<=.)(\1)
Matches:
"abca", "abca"