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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章