daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Oct 12th, 2018 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. static void regex(void)
  2. {
  3.    regex_t regex;
  4.    int reti;
  5.    char msgbuf[100];
  6.  
  7.    /* Compile regular expression */
  8.    reti = regcomp(&regex, "^a[[:alnum:]]", 0);
  9.    if (reti) {
  10.       fprintf(stderr, "Could not compile regex\n");
  11.       return;
  12.    }
  13.  
  14.    /* Execute regular expression */
  15.    reti = regexec(&regex, "abc", 0, NULL, 0);
  16.    if (!reti) {
  17.       puts("Match");
  18.    }
  19.    else if (reti == REG_NOMATCH) {
  20.       puts("No match");
  21.    }
  22.    else {
  23.       regerror(reti, &regex, msgbuf, sizeof(msgbuf));
  24.       fprintf(stderr, "Regex match failed: %s\n", msgbuf);
  25.       return;
  26.    }
  27.  
  28.    /* Free memory allocated to the pattern buffer by regcomp() */
  29.    regfree(&regex);
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top