我想匹配输入字符串中的所有“abc”。但是当输入“第一个 abc,第二个 abc,第三个 abc”时,我得到了以下结果。我还输出了ovector:
src: first abc, second abc, third abc
Matches 1
ovector: 6|9|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|
我的代码:
#include <stdio.h>
#include <string.h>
#include "pcre.h"
static const char my_pattern[] = "abc";
static pcre* my_pcre = NULL;
static pcre_extra* my_pcre_extra = NULL;
void my_match(const char* src)
{
printf("src: %s\n", src);
int ovector[30]={0};
int ret = pcre_exec(my_pcre, NULL, src, strlen(src), 0, 0, ovector, 30);
if (ret == PCRE_ERROR_NOMATCH){
printf("None match.\n");
}
else{
printf("Matches %d\n",ret);
}
printf("ovector: ");
for(int i=0;i<sizeof(ovector)/sizeof(int);i++){
printf("%d|",ovector[i]);
}
printf("\n");
return;
}
int main()
{
const char* err;
int erroffset;
my_pcre = pcre_compile(my_pattern, PCRE_CASELESS, &err, &erroffset, NULL);
my_pcre_extra = pcre_study(my_pcre, 0, &err);
my_match("first abc, second abc, third abc");
return 0;
}
我怎样才能得到所有的'abc',谢谢。