Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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;
- }
Add Comment
Please, Sign In to add comment