Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define PCRE2_CODE_UNIT_WIDTH 8
- #include <pcre2.h>
- #include <dlfcn.h>
- int main() {
- char buffer[1000];
- char *temp = buffer;
- while ((*temp++ = getchar()) != EOF);
- *--temp = '\0';
- //Compiling Regex
- int error;
- PCRE2_SIZE erroroffset;
- char errormessage[100];
- char pattern[30];
- strcpy(pattern, "Error");
- pcre2_code *regex = pcre2_compile(pattern, PCRE2_ZERO_TERMINATED, 0, &error, &erroroffset, NULL);
- pcre2_get_error_message(error, errormessage, 100);
- //Matching Regex Pattern
- pcre2_match_data *matches = pcre2_match_data_create_from_pattern(regex, NULL);
- int vector[1000];
- pcre2_dfa_match(regex, buffer, strlen(buffer), 0, 0, matches, NULL, vector, 1000);
- //Getting Substrings
- {
- PCRE2_UCHAR8** substrings;
- size_t* size;
- pcre2_substring_list_get(matches, &substrings, &size);
- PCRE2_UCHAR8** temp = substrings;
- char* substring;
- while(substring = *temp++){
- substring[*size++] = '\0';
- printf("Substring: %s", substring);
- }
- }
- //Program End
- pcre2_match_data_free(matches);
- pcre2_code_free(regex);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment