0
我提取字符串,需要檢查它是否符合特定的模式使用特殊字符正則表達式來找到Python中的比賽
<![any word]>
如果是的話我需要來取代它「」。我想下面的代碼
string1 = "<![if support]> hello"
string = re.sub(re.compile("<![.*?]>"),"",string1)
print(string)
但我得到的輸出作爲
<![if support]> hello
我希望得到的輸出爲hello。我在這裏做錯了什麼?
']'是不是一個字符類之外的特殊的正則表達式運算符。 'R 「」'就足夠了。 –