Using the following from Python – Check If Word Is In A String
>>> def findWholeWord(w):
... return re.compile(r'\b({0})\b'.format(w), flags=re.IGNORECASE).search
...
>>> findWholeWord('seek')('those who seek shall find')
<_sre.SRE_Match object at 0x22c1828>
>>> findWholeWord('seek')
<built-in method search of _sre.SRE_Pattern object at 0x22b8190>
>>> findWholeWord('seek')('those who seek shall find')
<_sre.SRE_Match object at 0x22c1828>
>>> findWholeWord('seek')('those who shall find')
Is this an error or this should be the result?
<_sre.SRE_Match object at 0x22c1828>
That match object is the result, and from that you have access to some more functions like
so on the returned object you can for example do
.span()to get the start and end index of the word you are looking for.