【发布时间】:2017-02-02 17:46:52
【问题描述】:
我将代码简化为我遇到的具体问题。
import re
pattern = re.compile(r'\bword\b')
result = pattern.sub(lambda x: "match", "-word- word")
我得到了
'-match- match'
但我想要
'-word- match'
编辑:
或者对于字符串"word -word-"
我想要
"match -word-"
【问题讨论】: