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 String exact match the following regex was used:
import re
print(re.findall('\\blocal\\b', "Hello, locally local test local."))
// ['local', 'local']
The problem is that in my case “local.” is different from “local”
How can I do that?
update:
What I need to do is to the replace the element which contains the work local.
print("Hello, locally local test local#".replace('local','we'))
// should result in
Hello, locally we test local#
It doesn’t make sense for a
findallif 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:Okay, an update related to:
I’d go for something like: