I am aware of multiple existing answers that suggest:
def contains(string, word):
return bool(re.search(rf"\b{word}\b", string))
But this pattern gives special treatment to alphanumeric character. For examples, contains("hello world!", "world!")
returns False
while contains("hello world!", "world")
returns True
.
I need a more 'naive' search pattern, one that matches a substring as long as it starts and ends with either the superstring's boundary or a space. (Desired behavior: opposite of the examples above.)