Hello everyone,
I want to check the email address with regex.And I attached my code,but whatever the parameter(char **email) is email or not , it always return “No Match”.
Can you help me to change it right? At the same time, I also want to get a better method from you.
Thank you~
code:
int is_email_valid
{
int status, i;
int cflags = REG_EXTENDED;
regmatch_t pmatch[1];
const size_t nmatch = 1;
regex_t reg;
const charpattern = “^w**@w*([-.]w*)*.w*([-.]w+)$";
char**buf = email;
regcomp(®, pattern, cflags);
status = regexec(®, buf, nmatch, pmatch, 0);
if (status REG_NOMATCH) {
printf(“No Match\n”);
}
else if (status 0) {
printf(”Match:“);
for (i = pmatch[0].rm_so; i < pmatch[0].rm_eo; ++i) {
putchar(buf);
}
printf(”");
}
regfree(®);
return 0;
}