Guest User

Untitled

a guest
Oct 12th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  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. }
Add Comment
Please, Sign In to add comment