Make your own word-boundary:
def exact_Match(phrase, word):
b = r'(s|^|$)'
res = re.match(b + word + b, phrase, flags=re.IGNORECASE)
return bool(res)
copy-paste from here to my interpreter:
>>> str1 = "award-winning blueberries"
>>> word1 = "award"
>>> word2 = "award-winning"
>>> exact_Match(str1, word1)
False
>>> exact_Match(str1, word2)
True
Actually, the casting to bool
is unnecessary and not helping at all. The function is better off without it:
def exact_Match(phrase, word):
b = r'(s|^|$)'
return re.match(b + word + b, phrase, flags=re.IGNORECASE)
note: exact_Match
is pretty unconventional casing. just call it exact_match.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…