fork download
  1. #include <sys/types.h>
  2. #include <regex.h>
  3. #include <stdio.h>
  4.  
  5.  
  6. int main(int argc, char *argv[]){ regex_t regex;
  7. int reti;
  8. char msgbuf[100];
  9.  
  10. /* Compile regular expression */
  11. reti = regcomp(&regex, "^[[:xdigit:]]\\{2\\}$", 0);
  12. if( reti ){ fprintf(stderr, "Could not compile regex\n"); return(1); }
  13.  
  14. /* Execute regular expression */
  15. reti = regexec(&regex, "ab", 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 1;
  26. }
  27.  
  28. /* Free compiled regular expression if you want to use the regex_t again */
  29. regfree(&regex);
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0s 2184KB
stdin
Standard input is empty
stdout
Match