如何使用python和re?
将数字后面的空格替换为逗号例如,
0,1,0 12 13 - > 0,1,0,12,13;
import re
text = "0, 1, 0 12 13"
matches = re.sub(r'(\d+)\s','*,', text)
print(matches)
但这给了我 0,1,*,*,*,
答案 0 :(得分:0)
另一种方式,没有重新:
text = "0, 1, 0 12 13"
text = text.replace(',', '') #We remove the commas (to leave them all the same)
text.replace(' ', ', ') # We replace spaces by comma and space