我无法为下面的场景找到正确的正则表达式:
让我们说:
a = "this is a sample"
Run Code Online (Sandbox Code Playgroud)
我希望匹配整个单词 - 例如,匹配"hi"应该返回False,因为"hi"它不是一个单词,并且"is"应该返回True,因为左侧和右侧没有字母字符.
字,字,字......对不起这个标题。
假设我想将字符串中的每个“是”实例替换为“否”。我可以只使用 string.replace()。但随之而来的就是这个问题:
string = "yes eyes yesterday yes"
new_str = string.replace("yes", "no")
# new_str -> "no eno noterday no"
Run Code Online (Sandbox Code Playgroud)
我怎样才能保留“眼睛”和“昨天”,将“是”改为“否”。