I'm scrapping a email address in a file with regex.
Unfortunately my regex rule can not match with to this string :
" <font size=-1><a href=mailto:mrnours@citeweb.net>_ MR NOURS _</a></font> "
;
I'm failling to find the reason why on stackoverflow, I hope someone could telle what is wrong on my rule.
This is my code to test it:
#include <stdio.h>
#include <stdlib.h>
#include <regex.h>
int main (void)
{
int match;
int err;
regex_t preg;
regmatch_t pmatch[5];
size_t nmatch = 5;
const char *str_request = " <font size=-1><a href=mailto:mrnours@citeweb.net>_ MR NOURS _</a></font> ";
const char *str_regex = "[a-zA-Z0-9][a-zA-Z0-9_.]+@[a-zA-Z0-9_]+\\.(com|net|[a-zA-Z]{2})$";
err = regcomp(&preg, str_regex, REG_EXTENDED);
if (err == 0)
{
match = regexec(&preg, str_request, nmatch, pmatch, 0);
nmatch = preg.re_nsub;
regfree(&preg);
if (match == 0)
{
printf ("match\n");
int start = pmatch[0].rm_so;
int end = pmatch[0].rm_eo;
printf("%d - %d\n", start, end);
}
else if (match == REG_NOMATCH)
{
printf("unmatch\n");
}
}
puts ("\nPress any key\n");
getchar ();
return (EXIT_SUCCESS);
}