题解 | #字符串通配符#
字符串通配符
http://www.nowcoder.com/practice/43072d50a6eb44d2a6c816a283b02036
import re
while True:
try:
a = input()
b = input()
a = a.lower()
b = b.lower()
a = a.replace('?','\w{1}').replace('.','\.').replace('*','\w*') #\w{1}代表匹配一个0-9且小写字母 \w*代表匹配多个0-9或小写字母
c = re.findall(a,b) #c中为b中与a匹配的字符串
if(b in c):
print('true')
else:
print('false')
except:
break
华为机试题解(prod.by kedao) 文章被收录于专栏
华为实习机试题解