我想寫一個正則表達式匹配的一系列文本的正則表達式查找和替換多個
[[any text or char her]]
的所有情況。
如:
My name is [[Sean]]
There is a [[new and cool]] thing here.
這一切工作正常使用我的正則表達式。
data = "this is my tes string [[ that does some matching ]] then returns."
p = re.compile("\[\[(.*)\]\]")
data = p.sub('STAR', data)
問題是,當我有匹配發生的歷史的多個實例:[[你好]]和[[再見]]
例如:
data = "this is my new string it contains [[hello]] and [[bye]] and nothing else"
p = re.compile("\[\[(.*)\]\]")
data = p.sub('STAR', data)
這將匹配的開口支架你好,還有再見的左括號。我希望它能夠取代它們。
你應該inlude在你的問題的標籤編程語言,使人們可以幫助你更好的。 –