Python: Find Exact Match
I would like to find words with the exact match using the find(). But it seams that find() returns strings with partial match as well. Referring to previous posts in stackoverflow
Solution 1:
It doesn't make sense for a findall
if all you're returning is a list of what you're looking for... For this use case, I wouldn't bother with an re, and just use:
'Hello, locally local test local.'.split().count('local')
Okay, an update related to:
What I need to do is to the replace the element which contains the work local.
I'd go for something like:
re.sub(r'\blocal([\b\s])', r'we\1', s)
Post a Comment for "Python: Find Exact Match"