正则表达式匹配
发布时间:2020-12-13 22:38:22 所属栏目:百科 来源:网络整理
导读:实现一个正则表达式匹配,要求支持'.'和'*'。 '.'指单个字符, '*'指零或多个前面的字符。 函数原型: bool isMatch(const char *s,const char *p) 如: isMatch(“aa”,”a”) → false isMatch(“aa”,”aa”) → true isMatch(“aaa”,”aa”) → false i
实现一个正则表达式匹配,要求支持'.'和'*'。 '.'指单个字符, '*'指零或多个前面的字符。 函数原型: bool isMatch(const char *s,const char *p) 如: isMatch(“aa”,”a”) → false bool isMatch(const char *s,const char *p) { if (s == NULL || p == NULL) { return false; } if (*p == ' ') { return *s == ' '; } if (*(p+1) != '*') { if ((*s == *p) || ((*p == '.') && (*s != ' '))) { return isMatch(s+1,p+1); } return false; } while ((*s == *p) || ((*p == '.') && (*s != ' '))) { if (isMatch(s,p+2)) { return true; } s++; } return isMatch(s,p+2); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |