fork download
  1. #include <stdio.h>
  2. #include <regex.h>
  3. #include <stdlib.h>
  4.  
  5. #define REGEX "prefix:\\w+,\\w+,\\s*-?[0-9]{1,4}\\s*,\\s*-?[0-9]{1,4}\\s*,\\s*-?[0-9]{1,4}\\s*,\\w*"
  6.  
  7. const char *input = "prefix:string,string,-100,100,0,string";
  8. int main(){
  9.  
  10. int rc;
  11.  
  12. regex_t regex;
  13.  
  14. rc = regcomp(&regex, REGEX, REG_EXTENDED);
  15. if (rc != 0) {
  16. fprintf(stderr, "Could not compile regex\n");
  17. exit(1);
  18. }
  19.  
  20. rc = regexec(&regex, input, 0, NULL, 0);
  21. if (rc == 0) {
  22. printf("Match!\n");
  23. return 0;
  24. }
  25. else if (rc == REG_NOMATCH) {
  26. printf("No match\n");
  27. return -1;
  28. }
  29. else {
  30. perror("Error\n");
  31. exit(1);
  32. }
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 5512KB
stdin
Standard input is empty
stdout
Match!