I am trying to substring search
>>>str1 = 'this'
>>>str2 = 'researching this'
>>>str3 = 'researching this '
>>>"[^a-z]"+str1+"[^a-z]" in str2
False
>>>"[^a-z]"+str1+"[^a-z]" in str3
False
I wanted to True when looking in str3. what am I doing wrong?
You want Python’s re module:
I have a hunch you’re actually looking for the word “this”, not “this” with non-word characters around it. In that case, you should be using the word boundary escape sequence
\b.