I have a string in which the word local occurs many times. I used the find() function to search for this word, but it will also find e.g. locally. How can I match local exactly?
I have a string in which the word local occurs many times. I used
Share
For this kind of thing, regexps are very useful :
\b means word boundary, basically. Can be space, punctuation, etc.
Edit for comment :
You can remove flags=re.IGNORECASE if you don’t want to ignore the case, obviously.