【字符串】正则表达式匹配

# -*- 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

你可能感兴趣的:(【字符串】正则表达式匹配)