この「これはステートメントです」のような文字列があり、文字列を検索してこれに置き換えたい場合は、「この**ステートメント」としましょう
検索する文字列 this is a statement 、this si a statement 、this ia statement 、および任意の組み合わせ これらをこのtrim a ステートメントに変換します。つまり、this と a ステートメントの間の任意の単語の組み合わせ を別のセットのtrimに置き換えます funをnotfunに置き換えます。
これがプログラムです
import re
file=open('file','r+')
search=re.sub('this \(a_zA_Z0_9)+ a statement','\1trim',file),('this is fun','this is notfun',file)
file.close()
ファイルで何も変更されていないため、何かが正しくありません。
みんな、ありがとう。