with open(self.filename) as the_file:
    file_contents = the_file.read()
output = file_contents
for word in highlight_terms:
    regex = re.compile('\\b' + word + 's{0,1}', flags=re.IGNORECASE | re.
        VERBOSE)
subst = '\x1b[1;41m' + '\\g<0>' + '\x1b[0m'
output = re.sub(regex, subst, output)
print(output)
the_file.close()
Finding and substituting a list of words in a file using regex in Python