I have a txt file and I want to search for specific words there and save it in another txt file with the number of times that it has appeared. Example: I want to search for this words "jardim guanabara", "jd guanabara", "jd gb", "norte", "zona norte", "vale dos sonhos", "asa branca" and "joao paulo".
This is what I've tried until now, but I don't know very well how to handle this. Can you guys help me how can I write the right regex to find this words? I appreciate any help.
[import re
regex = r"((?<=zona )norte\w+|(?<=jardim )guanabara|(?<=jardim )gb\w+)|((?<=joao )paulo\w+|(?<=zn)norte|(?<=gato)dorm\w+)"
with open('file.txt','r') as f:
#input_file = f.readlines()
for line in f:
x = re.search(regex, line)
print(x)]
I expect some thing like this saved into another txt file. 1