/* simple regex example */ #include #include #include #include int main(int argc, char *argv[]) { regex_t preg; char *regex, *match; int ret; /* get input from user */ if (argc != 3) { printf("Usage: %s \n", argv[0]); return EXIT_FAILURE; } regex = argv[1]; match = argv[2]; /* compile the regex */ ret = regcomp(&preg, regex, REG_EXTENDED); if (ret) { /* handle error */ char err[256]; if (regerror(ret, &preg, err, sizeof(err))) fprintf(stderr, "regcomp failed: %s\n", err); else fprintf(stderr, "regcomp failed\n"); return EXIT_FAILURE; } /* match the regex */ if (regexec(&preg, match, 0, NULL, 0) == 0) printf("match !\n"); else printf("no match !\n"); /* clean up */ regfree(&preg); return EXIT_SUCCESS; }