#include<stdio.h> #include<regex.h> int main(int argc, char** argv) { if(IsLegalPage("http://www.baidu.com")) printf("该网页合法/n"); else printf("该网页不合法!!!/n"); return 0; } /* 函数说明:判断网页是否合法 * 输入参数:需要判断的网址 * 返回结果:网页是否合法(合法1,不合法0) */ int IsLegalPage(char* s_tmp) { char* pattern="(https?)://.*(/.cn|/.com|/.htm|/.html|/.aspx?|/.jsp|/.php|/|/#)$"; printf("pattern=%s/n",pattern); int z=0; regex_t reg; regmatch_t pm[1]; z=regcomp(®,pattern,REG_EXTENDED|REG_ICASE); z=regexec(®,s_tmp,1,pm,0); if(z!=0) return 0; else return 1; regfree(®); }