I'm trying to find specific words in a string using re.findall method, and so far I have successfully implemented the code but the issue is that my code is case sensitive and I'm trying case insensitive. I have tried setting flag re.IGNORECASE etc but no luck, kindly help me out. Here is my code:
from collections import Counter
vocab = ['Chrome', 'Mozilla', 'Opera', 'iPhone', 'Spider']
with open('Assignment_log.txt', 'r') as file:
data = file.read().replace('\n', '')
wordcount = dict((x,0) for x in vocab)
for w in re.findall(r"\w+", data, re.IGNORECASE):
if w in wordcount:
wordcount[w] += 1
wordcount = Counter(wordcount)
print(wordcount)
Output: Counter({'Mozilla': 339, 'Chrome': 35, 'Opera': 16, 'iPhone': 2, 'Spider': 0})
here 'spider' is case sensitive so, I got zero counts.