【剑指offer】题53:正则表达式匹配

前端之家收集整理的这篇文章主要介绍了【剑指offer】题53:正则表达式匹配前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

bool@H_301_4@ match_core(char@H_301_4@* str@H_301_4@,char@H_301_4@ * pattern)
{
    if@H_301_4@ (*str@H_301_4@ == '\0'@H_301_4@&&*pattern == '\0'@H_301_4@)
    {
        return@H_301_4@ true@H_301_4@;
    }
    if@H_301_4@ (*str@H_301_4@ != '\0'@H_301_4@ && *pattern == '\0'@H_301_4@) 
    {
        return@H_301_4@ false@H_301_4@;
    }
    if@H_301_4@ (*(pattern+1@H_301_4@)=='*'@H_301_4@)
    {
        if@H_301_4@ ((*pattern == *str@H_301_4@)||(*pattern=='.'@H_301_4@&&*str@H_301_4@!='\0'@H_301_4@))
        {
            return@H_301_4@ match_core(str@H_301_4@ + 1@H_301_4@,pattern + 2@H_301_4@)
                || match_core(str@H_301_4@ + 1@H_301_4@,pattern)
                || match_core(str@H_301_4@,pattern + 2@H_301_4@);
        }
        else@H_301_4@
        {
            return@H_301_4@ match_core(str@H_301_4@,pattern + 2@H_301_4@);
        }
    }
    if@H_301_4@ ((*str@H_301_4@ == *pattern) || (*pattern == '.'@H_301_4@&&*str@H_301_4@ != '\0'@H_301_4@))
    {
        return@H_301_4@ match_core(str@H_301_4@ + 1@H_301_4@,pattern + 1@H_301_4@);
    }
    return@H_301_4@ false@H_301_4@;
}

bool@H_301_4@ match@H_301_4@(char@H_301_4@* str@H_301_4@,char@H_301_4@* pattern)
{
    if@H_301_4@ (str@H_301_4@==NULL||pattern==NULL)
    {
        return@H_301_4@ false@H_301_4@;
    }
    return@H_301_4@ match_core(str@H_301_4@,pattern);
}

猜你在找的正则表达式相关文章