-1

I need find a repeated sequences of same my_string = 'ABCD' in string my_data = 'ABCDABCDRRRABCD' and return the longest one 'ABCDABCD'. If I use result = ([max(i) for i in re.findall(r'((ABCD)\2+)', data)]) It's works fine, but I can't put a variable my_string so I can use it for difference strings in some loop.

1 Answers1

-1

To put variable inside of regular expression you can use .format

result = ([max(i) for i in re.findall(r'(({0})\2+)'.format(my_string), my_data)])