Skip to content

Instantly share code, notes, and snippets.

@BenBergman
Created October 26, 2012 15:16
Show Gist options
  • Save BenBergman/3959357 to your computer and use it in GitHub Desktop.
Save BenBergman/3959357 to your computer and use it in GitHub Desktop.
// String I want to match: "SWI9600M_01\\.00\\.09\\.03AP R2492 CARMD-EN-10526 2011/07/01 19:31:09\n"
int validate_string_with_regex(const char *string, const char *regex_str) {
regex_t regex;
/* Compile regular expression */
int reti = regcomp(&regex, regex_str, REG_EXTENDED);
if (reti != 0) {
fprintf(stderr, "Could not compile regex\n");
return reti;
}
/* Execute regular expression */
reti = regexec(&regex, string, 0, NULL, 0);
return reti;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment