When you use [.*]
it does a greedy match, so everything from [a
till b]
is matched and substituted for the empty string ''
.
When you use [.?]
, it matches anychar .
zero or 1 time ?
which are inside []
. And so [a]
and [b]
are matched.
import re
with open('file1.txt') as file1:
file1 = file1.read()
test = re.sub(r'[([].?[)]]', '', file1)
print(test)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…