Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main() {
- char buffer[10000];
- char *temp = buffer;
- while ((*temp++ = getchar()) != EOF);
- *--temp = '\0';
- //Compiling Regex
- int error;
- PCRE2_SIZE erroroffset;
- char errormessage[100];
- pcre2_code *regex = pcre2_compile("Error", PCRE2_ZERO_TERMINATED, 0, &error, &erroroffset, NULL);
- pcre2_get_error_message(error, errormessage, 100);
- //Matching Regex Pattern
- pcre2_match_data *matches;
- int numresults = pcre2_match(regex, buffer, 30, 0, 0, matches, NULL);
- pcre2_get_error_message(numresults, errormessage, 100);
- if(numresults == PCRE2_ERROR_NOMATCH)
- return 0;
- //Getting Substrings
- for(int i=0; i < numresults; i++){
- char match[30];
- size_t *matchlen;
- pcre2_substring_copy_bynumber(matches, i, match, matchlen);
- printf("%d: %s\n", i, match);
- }
- //Program End
- pcre2_match_data_free(matches);
- pcre2_code_free(regex);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment