我试图在txt文件的文本之前,之内或之后找到括号,我通过正则表达式尝试它,它给出了{}和[]的正确结果,但不是() 代码是
import re;
file="C:/Python26/test.txt";
f=open("paranthesis.txt",'w');
pattern ='[^[]*\[([^]]*)\]|\(|\)|\]|\[|\}|\{';
with open(file,'r') as rf:
lines = rf.readlines();
## c=0;
for word in lines:
if re.match(pattern, word):
f.write(word.strip("\n")+"\t"'1'"\n");
## f.write('1'"\n");
## c=c+1;
else:
f.write(word.strip("\n")+"\t"'0'"\n");
## f.write('0'"\n");
## c=c+1;
## print c;
f.close();
此代码针对文本中的每个[]和{}生成“1”,但未针对()
给出结果