0

I am trying to find all substrings of a given type: xyx or xxyxx and so on. For example in string: abcbaba possible substrings are: bcb, bab and aba.

My simplest pattern is: r'([a-z]+)[a-z](\1)' but it doesn't match substring bab. It looks like this pattern can only see the substings next to each other but not overlapping. The second problem is that regex also matches substrings of the same letters, and shouldn't :(

I am asking for a hint or some help. I'm learning regex using python.

0 Answers0