fork(8) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <regex.h>
  4.  
  5. int main (void)
  6. {
  7. int match;
  8. int err;
  9. regex_t preg;
  10. regmatch_t pmatch[5];
  11. size_t nmatch = 4; //5;
  12. const char *str_request = " <font size=-1><a href=mailto:mrnours@citeweb.net>_ MR NOURS _</a></font> ";
  13.  
  14. const char *str_regex = "([a-zA-Z0-9][a-zA-Z0-9_.]+@[a-zA-Z0-9_]+\\.(com|net|[a-zA-Z]{2}))([^a-zA-Z]|$)";
  15.  
  16. err = regcomp(&preg, str_regex, REG_EXTENDED);
  17. if (err == 0)
  18. {
  19. match = regexec(&preg, str_request, nmatch, pmatch, 0);
  20. nmatch = preg.re_nsub;
  21. regfree(&preg);
  22. if (match == 0)
  23. {
  24. printf ("match\n");
  25. int start = pmatch[1].rm_so; // <- Changed from 0 to 1
  26. int end = pmatch[1].rm_eo; // <- Changed from 0 to 1
  27. printf("%d - %d\n\"%.*s\"", start, end, pmatch[1].rm_eo - pmatch[1].rm_so, &str_request[pmatch[1].rm_so]);
  28. }
  29. else if (match == REG_NOMATCH)
  30. {
  31. printf("unmatch\n");
  32. }
  33. }
  34. puts ("\nPress any key\n");
  35. getchar ();
  36. return (EXIT_SUCCESS);
  37. }
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
match
38 - 57
"mrnours@citeweb.net"
Press any key