-6

Found the hugh bothwell answer

Python - Check If Word Is In A String

quite useful but now i want this to happen

 findWholeWord('object')('object test')    # -> <match object>
 findWholeWord('object')('object-group')                   # -> None

anybody?

Community
  • 1
  • 1

2 Answers2

2
(?:^|(?<=\s))object(?=\s|$)

You can use this regex with re.findall to check if it is there or not.

Something like

if re.findall(r"(?:^|(?<=\s))object(?=\s|$)",test_str):
    print "yes present"
vks
  • 67,027
  • 10
  • 91
  • 124
0

use regex:

'object(?=[\W\D\S\s]*?)'

This should work.

ha9u63a7
  • 6,233
  • 16
  • 73
  • 108