Handling backreferences to capturing groups in re.sub replacement pattern

问题:

I want to take the string 0.71331, 52.25378 and return 0.71331,52.25378 - ie just look for a digit, a comma, a space and a digit, and strip out the space.我想取字符串0.71331, 52.25378并返回0.71331,52.25378 - 即只查找一个数字、一个逗号、一个空格和一个数字,然后0.71331,52.25378空格。

This is my current code:这是我当前的代码:

coords = '0.71331, 52.25378'
coord_re = re.sub("(\d), (\d)", "\1,\2", coords)
print coord_re

But this gives me 0.7133,2.25378 .但这给了我0.7133,2.25378 What am I doing wrong?我究竟做错了什么?


解决方案:

参考: https://stackoom.com/en/question/YE4p
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章