Added gnu_regex.c

This commit is contained in:
anon 2024-03-10 15:57:35 +01:00
parent 2372ccb95f
commit 87d082cba2

21
gnu_regex.c Normal file
View File

@ -0,0 +1,21 @@
#include <stdio.h>
#include <regex.h>
int main() {
regex_t regex;
regcomp(&regex, "pattern", 0);
char test_str[] = "This is a pattern example.";
regmatch_t pmatch[1];
if (regexec(&regex, test_str, 1, pmatch, 0) == 0) {
printf("Pattern found at position %d.\n", pmatch[0].rm_so);
} else {
printf("Pattern not found.\n");
}
regfree(&regex);
return 0;
}