#include#include #include #include #include int main(){ char *bematch = "hhhericchd@gmail.com"; char *pattern = "h{3,10}(.*)@(.{5}..*)$"; char errbuf[1024]; char match[100]; regex_t reg; int err,nm = 10; int len, i; regmatch_t pmatch[nm]; if(regcomp(®,pattern,REG_EXTENDED) < 0){ regerror(err,®,errbuf,sizeof(errbuf)); printf("err:%sn",errbuf); } err = regexec(®,bematch,nm,pmatch,0); if(err == REG_NOMATCH){ printf("no matchn"); exit(-1); }else if(err){ regerror(err,®,errbuf,sizeof(errbuf)); printf("err:%sn",errbuf); exit(-1); } for(i=0;i<10 && pmatch[i].rm_so!=-1;i++) { len = pmatch[i].rm_eo-pmatch[i].rm_so; if(len){ memset(match,' ',sizeof(match)); memcpy(match,bematch+pmatch[i].rm_so,len); printf("%sn",match); } } return 0; }