Skip to content

Instantly share code, notes, and snippets.

@JakubOboza
Created December 1, 2008 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JakubOboza/30811 to your computer and use it in GitHub Desktop.
Save JakubOboza/30811 to your computer and use it in GitHub Desktop.
Pcre lib shoot
#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