【字符串】正则表达式匹配
2019-08-28 本文已影响0人
一个想当大佬的菜鸡
# -*- coding:utf-8 -*-
class Solution:
def match(self, s, pattern):
if s=='' and pattern=='':
return True
if s!='' and pattern=='':
return False
if len(pattern)>1 and pattern[1]=='*':
if s and (pattern[0]=='.' or pattern[0]==s[0]):
return self.match(s,pattern[2:]) or self.match(s[1:],pattern[2:]) or self.match(s[1:],pattern)
else:
return self.match(s,pattern[2:])
if s and (pattern[0]=='.' or pattern[0]==s[0]):
return self.match(s[1:],pattern[1:])
return False