tests/C_C++/gnu_regex.c
2024-07-22 19:37:02 +02:00

22 lines
409 B
C

#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;
}