Say, for example, I want to check if the word test is in a string. Normally, I’d just:
if 'test' in theString
But I want to make sure it’s the actual word, not just the string. For example, test in “It was detestable” would yield a false positive. I could check to make sure it contains (\s)test(\s) (spaces before and after), but than “…prepare for the test!” would yield a false negative. It seems my only other option is this:
if ' test ' in theString or ' test.' in theString or ' test!' in theString or.....
Is there a way to do this properly, something like if 'test'.asword in theString?
This will look for word boundaries on either end of
test. From the docs,\b: