fork download
  1. #include <stdio.h>
  2. #include <regex.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. #define MEM_STEP 1000
  7.  
  8. char* input_text(){
  9. int sizetext = MEM_STEP;
  10. int index = 0;
  11. char c;
  12. char* text = malloc(MEM_STEP);
  13. if (!text) {return NULL;}
  14.  
  15. while((c = getchar()) != EOF){
  16. if(index >= sizetext-1){
  17. sizetext+=MEM_STEP;
  18. text = realloc(text,sizetext);
  19. if (!text) {return NULL;}
  20. }
  21. text[index]=c;
  22. index++;
  23. if (strstr(text, "Fin.") != NULL) {
  24. break;
  25. }
  26. }
  27. text[index]='\0';
  28. return text;
  29. }
  30. int main()
  31. {
  32. char* text = input_text();
  33.  
  34. regex_t regex;
  35.  
  36. char* pattern = "([A-Za-z0-9_]+)@([A-Za-z0-9_-]+):\\s?~\\s?# (.+)";
  37.  
  38. regcomp(&regex, pattern, REG_EXTENDED);
  39.  
  40. regmatch_t match[4];
  41.  
  42. while (regexec(&regex, text, 4, match, 0) == 0)
  43. {
  44. printf("%.*s - ", match[0].rm_eo - match[0].rm_so, text + match[0].rm_so);
  45. text += match[0].rm_eo;
  46. }
  47. regfree(&regex);
  48. return 0;
  49. }
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty