我正在尝试在 python 中使用正则表达式从文件中提取某些单词,但我无法得到它。我的原始文件看起来像
List/VB
[ the/DT flights/NNS ]
from/IN
我希望输出是
List VB
the DT
flights NNS
from IN
我写了以下代码:
import re
with open("in.txt",'r') as infile, open("out.txt",'w') as outfile:
for line in infile:
if (re.match(r'(?:[\s)?(\w\\\w)',line)):
outfile.write(line)