Regular Expression Matching

bool isMatch(char* s, char* p) {
    if(*s=='\0'){
        if(*p=='\0'||(*(p+1)=='*'&&isMatch(s,p+2)))
        return true;
        else
        return false;
    }
    if(*p=='\0')return false;
    if(*(p+1)!='*'){
        if(*s==*p||*p=='.')
        return isMatch(s+1,p+1);
        return false;
    }else{
        
        if(*s!=*p&&*p!='.') return isMatch(s,p+2);
        
        if(isMatch(s,p+2)) return true;
        
        while(*s==*p||*p=='.'){
            if(isMatch(++s,p+2))
                return true;
            if(*s=='\0')return false;
        }
        return false;
        //return isMatch(s,p+2)||isMatch(s+1,p)||isMatch(s+1,p+2);
    }
}

解析:

 

posted @ 2016-04-08 11:32  舒克_贝塔  阅读(158)  评论(0编辑  收藏  举报