I want to extract a whole word from a sentence. Thanks to this answer,
import re
def findWholeWord(w):
return re.compile(r'\b({0})\b'.format(w), flags=re.IGNORECASE).search
I can get whole words in cases like:
findWholeWord('thomas')('this is Thomas again') # -> <match object>
findWholeWord('thomas')('this is,Thomas again') # -> <match object>
findWholeWord('thomas')('this is,Thomas, again') # -> <match object>
findWholeWord('thomas')('this is.Thomas, again') # -> <match object>
findWholeWord('thomas')('this is ?Thomas again') # -> <match object>
where symbols next to the word don't bother.
However if there's a number it doesn't find the word.
How should I modify the expression to match cases where there's a number next to the word? Like:
findWholeWord('thomas')('this is 9Thomas, again')
findWholeWord('thomas')('this is9Thomas again')
findWholeWord('thomas')('this is Thomas36 again')