【发布时间】:2016-12-02 04:54:25
【问题描述】:
我想做一些特别的 re.sub 输入
string = "\"hope\" and \"love\" or \"passion\" and (\"luck\" or \"money\") "
word_list = ['hope', 'love', 'passion', 'money', 'luck']
希望的输出是
'0 and 1 or 2 and (4 or 3)
我试试
print(re.sub("\"([^\"]*)\"", stri.index(r'\g<1>') , string))
但是没有用
【问题讨论】:
-
不要全部转义,请使用单引号。
标签: python regex python-3.x