Created
November 30, 2019 16:42
-
-
Save goranmoomin/8b5407a3f53fa243ff1126bdff96142c to your computer and use it in GitHub Desktop.
Check if regex is a valid POSIX Extended regex
This file contains 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 <stdio.h> | |
#include <regex.h> | |
int main(void) { | |
char pattern[256]; | |
scanf("%s", pattern); | |
regex_t regex; | |
const int errcode = regcomp(®ex, (const char *)pattern, REG_EXTENDED); | |
if(errcode == 0) { | |
printf("regex valid\n"); | |
return 0; | |
} | |
char errbuf[256]; | |
regerror(errcode, ®ex, errbuf, sizeof(errbuf) / sizeof(char)); | |
printf("%s\n", errbuf); | |
return errcode; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment