1.test_str = 'Kobe is one of the best basketball players'
result = test_str.replace('one','on')
print(result)
Kobe is on of the best basketball players
我想要的结果是替换完整的单词,而不是单词中的一部分,只有完全匹配才能替换
- test_str = 'Kobe is one of the best basketball players'
result = test_str.replace('one','on')
print(result)
Kobe is one of the best basketball players
这里没有完全的匹配不替换才对
而且也不能使用下列的方法,因为我还有其他的单词需要匹配
patt = re.compile(f'^{uk}$')
text = re.sub(patt,us,text)