4

私はこれを行う必要があります:

text = re.sub(r'\]\n', r']', text)

ただし、変数としてfindおよびを使用すると、次のようになります。replace

find = '\]\n'
replace = ']'
text = re.sub(find, replace, text)

r(生)どこに入れればいいですか?文字列ではありません。

4

3 に答える 3

2

保つr'...'

find = r'\]\n'
replace = r']'
text = re.sub(find, replace, text)

またはと行く

find = '\\]\\n'
replace = ']'
text = re.sub(find, replace, text)
于 2012-11-26T13:43:40.560 に答える