Advertisement
Guest User

Untitled

a guest
Oct 8th, 2012
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.39 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <pcre.h>
  3. int main () {
  4. pcre *re;
  5.     const char *error;
  6.     const char *subject ="test тест";
  7.     int erroffset, rc;
  8.     int ovector[30];
  9.    
  10.     re = pcre_compile(
  11.             "^[А-Яа-я\\040]+$",              /* the pattern */
  12.             0,                     /* default options */
  13.             &error,               /* for error message */
  14.             &erroffset,           /* for error offset */
  15.             NULL );                /* use default character tables */
  16.    
  17.     if (re == NULL)
  18.   {
  19.    printf("PCRE compilation failed at offset %d: %s\n", erroffset, error);
  20.   return 1;
  21.   }
  22.  
  23. rc = pcre_exec(
  24.     re,                   /* the compiled pattern */
  25.     NULL,                 /* no extra data - we didn't study the pattern */
  26.     subject,              /* the subject string */
  27.     sizeof(*subject),     /* the length of the subject */
  28.     0,                    /* start at offset 0 in the subject */
  29.     0,                    /* default options */
  30.     ovector,              /* output vector for substring information */
  31.     30);
  32.     if (rc < 0) {
  33.         switch(rc) {
  34.         case PCRE_ERROR_NOMATCH: printf("No match\n"); break;
  35.                 case PCRE_ERROR_BADUTF8: printf("BAD UTF8!!!\n"); break;
  36.         default: printf("Matching error %d\n", rc); break;
  37.         }
  38.      
  39.  pcre_free(re);
  40. return 1;
  41. }
  42.  
  43. printf("rc: %d\n",rc);
  44. pcre_free(re);
  45. return 0;
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement