import re
def find():
txt = 'Hi, I am Shirley Hilton. I am his wife.'
w=re.findall(r'%s'% x,txt)
if w:
print(w)
else:
print('not match')
x='hi'
find()
x='Hi'
find()
x='\bhi\b'
find()
输出结果:
前面 2 个正常,后面这个 x='\bhi\b'就不对了。
def find():
txt = 'Hi, I am Shirley Hilton. I am his wife.'
w=re.findall(r'%s'% x,txt)
if w:
print(w)
else:
print('not match')
x='hi'
find()
x='Hi'
find()
x='\bhi\b'
find()
输出结果:
前面 2 个正常,后面这个 x='\bhi\b'就不对了。