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)