fork(4) 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 = "GET http://w...content-available-to-author-only...e.com HTTP/1.1";
  13.  
  14. const char *str_regex = "([A-Za-z]+) +(http?://.*) +(HTTP/[0-9][.][0-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[1].rm_eo - pmatch[1].rm_so, &str_request[pmatch[1].rm_so]);
  24. printf("\"%.*s\"\n", pmatch[2].rm_eo - pmatch[2].rm_so, &str_request[pmatch[2].rm_so]);
  25. printf("\"%.*s\"\n", pmatch[3].rm_eo - pmatch[3].rm_so, &str_request[pmatch[3].rm_so]);
  26. }
  27. else if (match == REG_NOMATCH)
  28. {
  29. printf("unmatch\n");
  30. }
  31. }
  32. return 0;
  33. }
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
"GET"
"http://w...content-available-to-author-only...e.com"
"HTTP/1.1"