import re pattern = r'(?:AB)+A's = 'qqqqABqqqqqqABAqqqqqqABABABABAqqq'print(max(re.findall(pattern, s), key=len))
Standard input is empty
ABABABABA
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!