python - Getting exact string from a txt file -
let's trying number of times "the" appears in text file. how word "the" alone :
without getting others words 'the' substring :
- "there",
- "them",
- "their", etc.
word = 'the' reg = re.compile(r'\b%s\b' % word, re.i) open('textfile.containing.the','r') fin: print(len(reg.findall(fin.read()))
hope helps..
Comments
Post a Comment