BiggieJozin

Untitled

Sep 28th, 2022
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define PCRE2_CODE_UNIT_WIDTH 8
  5. #include <pcre2.h>
  6. #include <dlfcn.h>
  7.  
  8.  
  9. int main() {
  10. char buffer[1000];
  11.  
  12. char *temp = buffer;
  13. while ((*temp++ = getchar()) != EOF);
  14.  
  15. *--temp = '\0';
  16.  
  17.  
  18. //Compiling Regex
  19.  
  20. int error;
  21. PCRE2_SIZE erroroffset;
  22.  
  23. char errormessage[100];
  24. char pattern[30];
  25. strcpy(pattern, "Error");
  26. pcre2_code *regex = pcre2_compile(pattern, PCRE2_ZERO_TERMINATED, 0, &error, &erroroffset, NULL);
  27. pcre2_get_error_message(error, errormessage, 100);
  28.  
  29. //Matching Regex Pattern
  30.  
  31. pcre2_match_data *matches = pcre2_match_data_create_from_pattern(regex, NULL);
  32.  
  33. int vector[1000];
  34. pcre2_dfa_match(regex, buffer, strlen(buffer), 0, 0, matches, NULL, vector, 1000);
  35.  
  36.  
  37.  
  38.  
  39. //Getting Substrings
  40.  
  41. {
  42. PCRE2_UCHAR8** substrings;
  43. size_t* size;
  44.  
  45. pcre2_substring_list_get(matches, &substrings, &size);
  46.  
  47. PCRE2_UCHAR8** temp = substrings;
  48. char* substring;
  49. while(substring = *temp++){
  50. substring[*size++] = '\0';
  51. printf("Substring: %s", substring);
  52. }
  53. }
  54.  
  55.  
  56. //Program End
  57. pcre2_match_data_free(matches);
  58. pcre2_code_free(regex);
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment