I have a string that may have a repeated character pattern, e.g.
\'xyzzyxxyzzyxxyzzyx\'
I need to write a regex that would replace such str
Since you want the smallest repeating pattern, something like the following should work for you:
re.sub(r'^(.+?)\1+$', r'\1', input_string)
The ^ and $ anchors make sure you don't get matches in the middle of the string, and by using .+? instead of just .+ you will get the shortest pattern (compare results using a string like 'aaaaaaaaaa').