import re
text = "UURRUULLLRRDDDBBBUUU"
print( re.sub(r"(.)\1*", lambda x: "{}{}".format(len(x.group()), x.group(1)), text) )