import retext = "UURRUULLLRRDDDBBBUUU"print( re.sub(r"(.)\1*", lambda x: "{}{}".format(len(x.group()), x.group(1)), text) )
Standard input is empty
2U2R2U3L2R3D3B3U
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!