Given a text file we want to create another file containing only those lines that match a certain regular expression using python3

1
2
3
4
5
6
import re

with open("./in.txt", "r") as input_file, open("out.txt", "w") as output_file:
    for line in input_file:
        if re.match("(.*)import(.*)", line):
        print(line, file=output_file)