BiggieJozin

Untitled

Sep 28th, 2022
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. int main() {
  2. char buffer[10000];
  3.  
  4. char *temp = buffer;
  5. while ((*temp++ = getchar()) != EOF);
  6.  
  7. *--temp = '\0';
  8.  
  9.  
  10. //Compiling Regex
  11.  
  12. int error;
  13. PCRE2_SIZE erroroffset;
  14.  
  15. char errormessage[100];
  16. pcre2_code *regex = pcre2_compile("Error", PCRE2_ZERO_TERMINATED, 0, &error, &erroroffset, NULL);
  17. pcre2_get_error_message(error, errormessage, 100);
  18.  
  19. //Matching Regex Pattern
  20.  
  21. pcre2_match_data *matches;
  22. int numresults = pcre2_match(regex, buffer, 30, 0, 0, matches, NULL);
  23.  
  24.  
  25. pcre2_get_error_message(numresults, errormessage, 100);
  26. if(numresults == PCRE2_ERROR_NOMATCH)
  27. return 0;
  28.  
  29.  
  30.  
  31. //Getting Substrings
  32.  
  33.  
  34. for(int i=0; i < numresults; i++){
  35. char match[30];
  36. size_t *matchlen;
  37. pcre2_substring_copy_bynumber(matches, i, match, matchlen);
  38. printf("%d: %s\n", i, match);
  39. }
  40.  
  41.  
  42. //Program End
  43. pcre2_match_data_free(matches);
  44. pcre2_code_free(regex);
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment