#include <stdio.h>
#include <stdlib.h>
#include <regex.h>
int main() {
char input[] = "The quick brown fox jumps over the lazy dog";
char pattern[] = "\\b\\w{5}\\b";
regex_t regex;
int reti;
// Compile the regular expression
reti = regcomp(®ex, pattern, 0);
if (reti) {
fprintf(stderr, "Could not compile regex\n");
exit(EXIT_FAILURE);
}
// Execute the regular expression
reti = regexec(®ex, input, 0, NULL, 0);
if (!reti) {
printf("Match found!\n");
} else if (reti == REG_NOMATCH) {
printf("No match found.\n");
} else {
char msgbuf[100];
regerror(reti, ®ex, msgbuf, sizeof(msgbuf));
fprintf(stderr, "Regex match failed: %s\n", msgbuf);
exit(EXIT_FAILURE);
}
// Free the compiled regular expression
regfree(®ex);
return 0;
}