Here is the desired output:
"bacillus thurungensis" in "bacillus thurungensis"
TRUE
"bacillus thurungensis" in "Sentence containing bacillus thurungensis."
TRUE
"bacillus thurungensis" in "Subspecies bacillus thurungensis34"
FALSE
"bacillus thurungensis" in "bacillus thurungensis, bacillus genus"
TRUE
"bacillus thurungensis" in "Notbacillus thurungensis, must match word"
FALSE
Python typically thinks that any substring match is good, but I'm not looking for that. I want some regex or match operator to only yield true IF AND ONLY IF it sees the query as a separate word in the subject and not just a substring. How is this implimentable?
You can use regex instead:
And so on.
The
\b
is a word boundary. Also note the usage of ther
in the stringr"..."
.You can also use
compile
if you re going to use the regex over and over again: