codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include <stdio.h> #include <regex.h> // #define restrict /**/ // // int regex_match (char *restrict pattern, const char *restrict string, size_t sub_size, char *restrict sub[restrict], int cflags, int eflags, int verbose) { const int msg_size = 200; char msg[msg_size]; // regmatch_t pmatch[sub_size]; size_t n; size_t m; size_t d; // int status; regex_t re; // status = regcomp (&re, pattern, cflags); // if (status != 0) { if (verbose) { regerror (status, &re, msg, msg_size); fprintf (stderr, "%s\n", msg); } return (status); } // status = regexec (&re, string, sub_size, pmatch, eflags); // if (status != 0) { if (verbose) { regerror (status, &re, msg, msg_size); fprintf (stderr, "%s\n", msg); } } else { for (n=0; n < sub_size; n++) { for (d = 0, m = pmatch[n].rm_so; m >= 0 && m < pmatch[n].rm_eo; m++, d++) { sub[n][d] = string[m]; } sub[n][d] = '\0'; } } // regfree (&re); // return (status); } // // // int main (void) { int result; char *string = "Ciao amore mio"; char *re = "Ciao (amo)re"; char sub0[200]; sub0[0] = '\0'; char sub1[200]; sub1[0] = '\0'; char *sub[] = {sub0, sub1}; // result = regex_match (re, string, 2, sub, REG_EXTENDED, 0, 1); // if (result == 0) { printf ("Il modello \"%s\" trova corrispondenza ", re); printf ("nella stringa \"%s\", precisamente ", string); printf ("nella porzione \"%s\", mentre la ", sub[0]); printf ("sottostringa estratta รจ \"%s\".\n", sub[1]); } else { printf ("Il modello \"%s\" ", re); printf ("NON trova corrispondenza "); printf ("nella stringa \"%s\"\n", string); } return 0; }
Private
[
?
]
Run code
Submit