Advertisement
Guest User

pcre match empty string

a guest
Apr 14th, 2011
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <pcre.h>
  4. #define OVECCOUNT 30    /* should be a multiple of 3 */
  5. int main(int argc, char **argv)
  6. {
  7.   pcre *blankline,*re;
  8.   const char *error;
  9.   int erroffset;
  10.   int ovector[OVECCOUNT];
  11.   FILE *infile;
  12.   char buf[BUFSIZ];
  13.   char blank[] = "^\\s*$";
  14.   if (argc != 2)
  15.     {
  16.       printf("Filename required\n");
  17.       return 1;
  18.     }
  19.   blankline = pcre_compile(blank,PCRE_CASELESS,&error,&erroffset,NULL);    
  20.   if (!(infile = fopen(argv[1], "r"))) {
  21.         printf("Could not open input file");
  22.         exit(1);
  23.   }
  24.     while (fgets(buf, sizeof (buf), infile)) {
  25.       int n= strlen(buf);
  26.       buf[n - 1] = 0;
  27.       puts(buf);
  28.       rc = pcre_exec( blankline, NULL, buf, n, 0, 0, ovector, OVECCOUNT);
  29.       if (rc > 0){
  30.     break;
  31.       }
  32.     }
  33.     return(0);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement