比如说,我想检查单词test
是否在字符串中。通常,我只会:
if 'test' in theString
但我想确保它是实际单词,而不仅仅是字符串。例如,test
在“It was detestable”中会产生误报。我可以检查以确保它包含(\s)test(\s)
(之前和之后的空格),但不是“......准备测试!” 会产生假阴性。看来我唯一的其他选择是:
if ' test ' in theString or ' test.' in theString or ' test!' in theString or.....
有没有办法正确地做到这一点,比如if 'test'.asword in theString
?