将数字和R之间添加一个空格:
import re
s = "R1R2R3R4"
s_new = re.sub(r'(?<=\d)(R)', r' \1', s)
print(s_new) # 输出: R1 R2 R3 R4
s = "R1R2R3R4"
s_new = "" for i in range(len(s)): if i > 0 and s[i].isdigit() and s[i-1]=="R": s_new += " " s_new += s[i]
print(s_new) # 输出: R1 R2 R3 R4