Created
May 25, 2013 02:33
-
-
Save wmealing/5647692 to your computer and use it in GitHub Desktop.
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 <pcre.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
int main(int argc, char *argv[]) { | |
int i,rc; | |
const char *err; | |
int off; | |
char *regex = "hello,?\\sworld!?"; | |
pcre *re = pcre_compile(regex, 0, &err, &off, NULL); | |
if (re == NULL) { | |
printf("error %s in pattern %s at offset %u\n", err, regex, off); | |
exit(-1); | |
} | |
char *tests[] = { "hello, world!", "hello world!", "hello world" }; | |
/* now we coule loop over some input and test the regex */ | |
for(i=0; i < sizeof(tests)/sizeof(*tests); i++) { | |
rc = pcre_exec(re, NULL, tests[i], strlen(tests[i]), 0, 0, NULL, 0); | |
if (rc >= 0) { | |
printf("%s matches %s\n", tests[i], regex); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment