fork(3) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <regex.h>
  4.  
  5. int verifyPattern(char *pattern) {
  6. regex_t regex;
  7. int reti = regcomp(&regex, "^s/(\\\\.|[^\\\\/]+)+/(\\\\.|[^\\\\/]+)*/g$", REG_EXTENDED);
  8.  
  9. if (reti) {
  10. fprintf(stderr, "Could not compile regex\n");
  11. exit(1);
  12. }
  13.  
  14. reti = regexec(&regex, pattern, 0, NULL, 0);
  15. if (!reti) {
  16. puts("Match");
  17. } else if (reti == REG_NOMATCH) {
  18. puts("No match");
  19. } else {
  20. puts("Regex error");
  21. }
  22.  
  23. return 1;
  24. }
  25. int main (void)
  26. {
  27. verifyPattern("s/s/s/g");//Match
  28. verifyPattern("s/s//g");//Match
  29. verifyPattern("s//s/g");//No Match
  30. verifyPattern("s/s\\/s/g");//No match
  31. verifyPattern("s/s\\/s/text/text/text/g"); // No match
  32. }
Success #stdin #stdout 0s 2300KB
stdin
Standard input is empty
stdout
Match
Match
No match
No match
No match