Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. #include <regex.h>        
  2. regex_t regex;
  3. int reti;
  4. char msgbuf[100];
  5.  
  6. /* Compile regular expression */
  7. reti = regcomp(&regex, "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$", 0);
  8. if (reti) {
  9.     fprintf(stderr, "Could not compile regex\n");
  10.     exit(1);
  11. }
  12.  
  13. /* Execute regular expression */
  14. reti = regexec(&regex, "match mich doch du hurensohn", 0, NULL, 0);
  15. if (!reti) {
  16.     puts("Match");
  17. }
  18. else if (reti == REG_NOMATCH) {
  19.     puts("No match");
  20. }
  21. else {
  22.     regerror(reti, &regex, msgbuf, sizeof(msgbuf));
  23.     fprintf(stderr, "Regex match failed: %s\n", msgbuf);
  24.     exit(1);
  25. }
  26.  
  27. /* Free memory allocated to the pattern buffer by regcomp() */
  28. regfree(&regex);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement