Created
December 1, 2008 19:42
-
-
Save JakubOboza/30811 to your computer and use it in GitHub Desktop.
Pcre lib shoot
This file contains hidden or 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 <pcreposix.h> | |
#include <stdio.h> | |
int main(void) | |
{ | |
regex_t rx; | |
char *pat = "([0-2]?\\d{1,2})\\.([0-2]?\\d{1,2})\\.([0-2]?\\d{1,2})\\.([0-2]?\\d{1,2})"; | |
// More "ambitious" expression - "(?:([0-2]?\\d{1,2})\\.){3}([0-2]?\\d{1,2})"; | |
char *str = "123.45.67.89"; | |
regmatch_t match [6]; | |
int i; | |
regcomp (&rx, pat, 0); | |
regexec (&rx, str, 6, match, 0); | |
for (i=0; i<6; ++i) | |
{ | |
printf ("Perl-Compatible Regular Expression matched from character %i to %i: `%.*s'\n", | |
match[i].rm_so, match[i].rm_eo, | |
match[i].rm_eo-match[i].rm_so, | |
&str[match[i].rm_so]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment