What i need to do to use Regex in C?
Any help?
Any help?
#include // sys/types.h #include // regex.h int match(const char *string, char *pattern) { int status; regex_t re; if(regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) != 0) { return 0; } status = regexec(&re, string, (size_t)0, NULL, 0); regfree(&re); if(status != 0) { return 0; } return 1; }
regex_t pdata; regmatch_t pmatch[3]; if (error = regcomp(&pdata, "a\([bc]*\)a\([bc]*\)a", 0) { /* handle error */ } else if (error = regexec(&pdata, "xxxabcbabbcaxxx", 3, pmatch, 0) { /* handle error */ } else { printf("The regex matches from %d to %d.\n", pmatch[0].rm_so, pmatch[0].rm_eo); regfree(&pdata); }
Comment