引用re包
import re
string = "Hello, PythonWorld!"
search_word ="Python"
if re.findall(r"\b%s\b" % search_word ,string):
print("Match Found")
else:
print("Match Not Found")
import re
string = "Hello, PythonWorld!"
search_word ="PythonWorld"
if re.findall(r"\b%s\b" % search_word ,string):
print("Match Found")
else:
print("Match Not Found")
其中%后面的值会替换 %s