Created
October 9, 2014 05:41
-
-
Save sineer/63e9c7d02780ded70d33 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <regex.h> | |
int main() { | |
regex_t regex; | |
int ret; | |
chat msg[128]; | |
ret = regcomp(®ex, "^P[^:alnum:]", 0); | |
if (!ret) { | |
printf("Coulnd not compile regex\n"); | |
exit(1); | |
} | |
// Execute the Regular Expression | |
ret = regexec(®ex, "PAPA", 0, NULL, 0); | |
if (!ret) { | |
printf("MATCH!"); | |
} | |
else if (ret == RET_NOMATCH) { | |
printf("NO MATCH."); | |
} | |
else { | |
regerror(ret, ®ex, msg, sizeof(msg)); | |
printf("REGEX ERROR: %s\n", msg); | |
exit(1); | |
} | |
// Execute same Regular Expression that should NOT MATCH "P123" | |
ret = regexec(®ex, "P123", 0, NULL, 0); | |
if (!ret) { | |
printf("MATCH!"); | |
} | |
else if (ret == RET_NOMATCH) { | |
printf("NO MATCH."); | |
} | |
else { | |
regerror(ret, ®ex, msg, sizeof(msg)); | |
printf("REGEX ERROR: %s\n", msg); | |
exit(1); | |
} | |
// FREE the Regex! | |
regfree(®ex); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment