我希望做一些特殊的應用re.sub 輸入特殊應用re.sub python3
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))
但dosen't work
請不要轉義所有內容,請使用單引號。 –