fork(3) 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[4];
  11. size_t nmatch = 4;
  12. const char *str_request = "abc:1234567890@werty.wer.sdfg.net";
  13.  
  14. const char *str_regex = "(^|[^[:alnum:]_])(abc|def):[0-9]{10}@([A-Za-z0-9].*)";
  15. err = regcomp(&preg, str_regex, REG_EXTENDED);
  16. if (err == 0)
  17. {
  18. match = regexec(&preg, str_request, nmatch, pmatch, 0);
  19. nmatch = preg.re_nsub;
  20. regfree(&preg);
  21. if (match == 0)
  22. {
  23. printf("\"%.*s\"\n", pmatch[2].rm_eo - pmatch[2].rm_so, &str_request[pmatch[2].rm_so]);
  24. printf("\"%.*s\"\n", pmatch[3].rm_eo - pmatch[3].rm_so, &str_request[pmatch[3].rm_so]);
  25. }
  26. else if (match == REG_NOMATCH)
  27. {
  28. printf("unmatch\n");
  29. }
  30. }
  31. return 0;
  32. }
Success #stdin #stdout 0s 2244KB
stdin
Standard input is empty
stdout
"abc"
"werty.wer.sdfg.net"