Skip to content

Instantly share code, notes, and snippets.

@devpruthvi
Last active August 29, 2015 14:25
Show Gist options
  • Save devpruthvi/04ca9406b395c277cada to your computer and use it in GitHub Desktop.
Save devpruthvi/04ca9406b395c277cada to your computer and use it in GitHub Desktop.
#include <regex.h>
#include<stdio.h>
int main(int arg, char * argv[])
{
regex_t regex;
int reti;
char msgbuf[100];
reti = regcomp(&regex, "^[01]*1[01][01]$", 0);
if (reti) {
fprintf(stderr, "Could not compile regex\n");
}
reti = regexec(&regex,argv[1], 0, NULL, 0);
if (!reti) {
puts("Match");
}
else if (reti == REG_NOMATCH) {
puts("No match");
}
else {
regerror(reti, &regex, msgbuf, sizeof(msgbuf));
fprintf(stderr, "Regex match failed: %s\n", msgbuf);
return 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment