我在尝试查找电子邮件地址时遇到了问题。我不知道可能是什么问题:(
static int contains_mail(const unsigned char *buffer, int length, int detmode)
{
const char *reg_exp = "([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z0-9._%+-]+)";
regex_t regex;
int reti;
regmatch_t matches[2];
int start0, end0, start1, end1;
reti = regcomp(®ex, reg_exp, REG_EXTENDED);
if(reti){ fprintf(stderr, "Could not compile regex\n"); exit(1); }
reti = regexec(®ex, buffer, 2, matches, 0);
start0 = matches[0].rm_so;
end0 = matches[0].rm_eo;
start1 = matches[1].rm_so;
end1 = matches[1].rm_eo;
printf("start0: %d", start0);
printf("end0: %d", end0);
printf("start1: %d", start1);
printf("end1: %d", end1);
if( !reti ){
//printf("1");
return 1;
} else {
//printf("0");
return 0;
}
}
示例输入文件:
dfo gpdf eriowepower riwope d@b.pl rwepoir weporsdfi dsfdfasdas@sdfaasdas.pl OSIDQOPWIEPOQWIE sdfs@asdsa.pl
WERO IWUEOIRU OWIERU WOIER asdas@asdasd.pl
aposidasop aposdi aspod iaspodi aspoid aspodi sdfsddfsd@asdasd.pl
werowerowe
看起来它开始于:
start0: 28end0: 28start1: 1end1: 8
但是看起来它不知道电子邮件的结尾是什么所以我无法计算它:(