Skip to content

Instantly share code, notes, and snippets.

@goranmoomin
Created November 30, 2019 16:42
Show Gist options
  • Save goranmoomin/8b5407a3f53fa243ff1126bdff96142c to your computer and use it in GitHub Desktop.
Save goranmoomin/8b5407a3f53fa243ff1126bdff96142c to your computer and use it in GitHub Desktop.
Check if regex is a valid POSIX Extended regex
#include <stdio.h>
#include <regex.h>
int main(void) {
char pattern[256];
scanf("%s", pattern);
regex_t regex;
const int errcode = regcomp(&regex, (const char *)pattern, REG_EXTENDED);
if(errcode == 0) {
printf("regex valid\n");
return 0;
}
char errbuf[256];
regerror(errcode, &regex, 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