I want to search a file line by line for a particular word but I want to make sure that this particular word is being preceded and followed by a space.
I know that I have to do this using regex. I've been reading this guide but it's confusing to me how to apply both lookahead and lookbehind in the same statement.
How can I do this?
counter = 0
out = open('out.txt', 'w')
with open(original_db, 'r') as db:
for line in db:
if re.search(word, line, re.IGNORECASE):
counter += 1
out.write(line)
print("Entries found for word: " + str(counter))