Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中搜索精确单词_Python_Regex_String - Fatal编程技术网

在python中搜索精确单词

在python中搜索精确单词,python,regex,string,Python,Regex,String,找到了hugh bothwell的答案 非常有用,但现在我想这样做 findWholeWord('object')('object test') # -> <match object> findWholeWord('object')('object-group') # -> None findWholeWord('object')('objecttest')#-> FindHoleword('object')('objec

找到了hugh bothwell的答案

非常有用,但现在我想这样做

 findWholeWord('object')('object test')    # -> <match object>
 findWholeWord('object')('object-group')                   # -> None
findWholeWord('object')('objecttest')#->
FindHoleword('object')('object-group')#->None
有人吗?

使用正则表达式:

'object(?=[\W\D\S\s]*?)'
这应该行得通

(?:^|(?<=\s))object(?=\s|$)
if re.findall(r"(?:^|(?<=\s))object(?=\s|$)",test_str):
    print "yes present"