fork(2) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <regex.h>
  5.  
  6. int main () {
  7. regex_t regex;
  8. int reti;
  9. char msgbuf[100];
  10. const char *regIp = "^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?\\.){1,3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)?$";
  11. reti = regcomp(&regex, regIp, REG_EXTENDED);
  12. regerror(reti, &regex, msgbuf, sizeof(msgbuf));
  13. printf("Regex compile: %s.", msgbuf);
  14. reti = regexec(&regex, "192.168.100", 0, NULL, 0);
  15. if (!reti){
  16. puts("MATCH!!");
  17. } else if (reti == REG_NOMATCH) {
  18. puts("No match");
  19. } else {
  20. regerror(reti, &regex, msgbuf, sizeof(msgbuf));
  21. printf("Regex match failed: %s.", msgbuf);
  22. }
  23. }
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
Regex compile: Success.MATCH!!