看板 Python 關於我們 聯絡資訊
import re p = re.compile(r'(\D*)(\d*):(\d*)(.*)') s = 'XX22:67ddd' tmp = p.sub(r'\1---\2--\3--\4', s) print tmp 請問一下,如果我想要把 \1 \2 \3 \4 儲存起來的話有沒有什麼好方法呢? 還是我只能重複用 tmp1 = p.sub(r'\1', s) tmp2 = p.sub(r'\2', s) 這樣呢? 感謝回答! :> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 60.251.211.196
ibmibmibm:match+groups 06/13 01:41