我想取字符串0.71331, 52.25378并返回0.71331,52.25378- 即只需查找数字,逗号,空格和数字,并删除空格.
这是我目前的代码:
coords = '0.71331, 52.25378'
coord_re = re.sub("(\d), (\d)", "\1,\2", coords)
print coord_re
Run Code Online (Sandbox Code Playgroud)
但这给了我0.7133,2.25378.我究竟做错了什么?
我正在尝试使用python运行正则表达式进行替换,如下所示:
a = "%I'm a sentence.|"
re.sub(r"%(.*?)\|", "<\1>", a)
Run Code Online (Sandbox Code Playgroud)
然后b = <\1>,但我想得到结果<I'm a sentences.>
我该怎么做到这一点?我试图分组I'm a sentence,但我觉得我做错了,所以结果不能保持第1组.如果您有任何想法,请告诉我.非常感谢你提前!