,有以下疑问:
部分源码:
[code=c]pcre *re; const char *error; int erroffset; int ovector[5000]; int rc,i; char pattern [] = "http://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%%&=]*)?"; if(NULL == (re = pcre_compile(pattern,&error,&erroffset,NULL))) { printf("%d:%s\n",erroffset,error); return 1; } rc = pcre_exec(re,NULL,sendbuf,strlen(sendbuf),ovector,5000); if (rc < 0) { //如果没有匹配,返回错误信息 if (rc == PCRE_ERROR_NOMATCH) printf("Sorry,no match ...\n"); else printf("Matching error %d\n",rc); pcre_free(re); return 1; } for (i = 0; i < rc; i++) { //分别取出捕获分组 $0整个正则公式 $1第一个() char *substring_start = sendbuf + ovector[2*i]; int substring_length = ovector[2*i+1] - ovector[2*i]; printf("$%2d: %.*s\n",i,substring_length,substring_start); } pcre_free(re); [/code]执行结果为: $ 0: http://s1.bdstatic.com/r/www/cache/static/global/img/icons_4879d3b8.png $ 1: bdstatic. $ 2: /r/www/cache/static/global/img/icons_4879d3b8.png 但是我用网上的正则表达式测试工具一样的正则表达式一样的文本出现的结果如下: http://s1.bdstatic.com/r/www/cache/static/global/img/icons_4879d3b8.png http://s1.bdstatic.com/r/www/cache/static/global/img/icons_5a07887b.gif http://s1.bdstatic.com/r/www/cache/static/global/img/icons_4879d3b8.png http://s1.bdstatic.com/r/www/cache/static/global/img/icons_5a07887b.gif http://www.baidu.com/img/sug_bd.png http://s1.bdstatic.com/r/www/cache/static/global/img/wsCloseBtn2_4a84c812.png http://www.baidu.com/ http://www.baidu.com/s? http://www.baidu.com/s? http://www.baidu.com/gaoji/preferences.html 。。。。 问什么会有这么大的差别啊。 原文链接:https://www.f2er.com/regex/361946.html