I have a character string 'aabaacaba'
. Starting from left, I am trying to get substrings of all sizes >=2, which appear later in the string. For instance, aa
appears again in the string and so is the case with ab
.
I wrote following regex code:
re.findall(r'([a-z]{2,})(?:[a-z]*)(?:\1)', 'aabaacaba')
and I get ['aa'] as answer. Regular expression misses ab pattern. I think this is because of overlapping characters. Please suggest a solution, so that the expression could be fixed. Thank you.