次のすべてのケースに一致する正規表現を作成しようとしています
[[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)
問題は、[[hello]] と [[bye]] という一致のインスタンスが複数ある場合です。
例えば:
data = "this is my new string it contains [[hello]] and [[bye]] and nothing else"
p = re.compile("\[\[(.*)\]\]")
data = p.sub('STAR', data)
これは、hello の開始ブラケットと bye の終了ブラケットに一致します。両方交換してほしい。