I have a string in which the word \"LOCAL\" occurs many times. I used the find()
function to search for this word but it returns another word \"Locally\" as wel
Using Pyparsing:
import pyparsing as pp
def search_exact_word_in_string(phrase, text):
rule = pp.ZeroOrMore(pp.Keyword(phrase)) # pp.Keyword() is case sensitive
for t, s, e in rule.scanString(text):
if t:
return t
return False
text = "Local locally locale"
search = "Local"
print(search_exact_word_in_string(search, text))
Which Yields:
['Local']