I am trying to extract certain words from a file using regex in python but I am unable to get it. My original file looks like
List/VB
[ the/DT flights/NNS ]
from/IN
and I want the output to be
List VB
the DT
flights NNS
from IN
I wrote the following code:
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)