Guest User

Untitled

a guest
Feb 21st, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include <pcreposix.h>
  2. #include <stdio.h>
  3.  
  4. int main(void)
  5. {
  6. regex_t rx;
  7. char *pat = "([0-2]?\\d{1,2})\\.([0-2]?\\d{1,2})\\.([0-2]?\\d{1,2})\\.([0-2]?\\d{1,2})";
  8. // More "ambitious" expression - "(?:([0-2]?\\d{1,2})\\.){3}([0-2]?\\d{1,2})";
  9. char *str = "123.45.67.89";
  10. regmatch_t match [6];
  11. int i;
  12.  
  13. regcomp (&rx, pat, 0);
  14. regexec (&rx, str, 6, match, 0);
  15.  
  16. for (i=0; i<6; ++i)
  17. {
  18. printf ("Perl-Compatible Regular Expression matched from character %i to %i: `%.*s'\n",
  19. match[i].rm_so, match[i].rm_eo,
  20. match[i].rm_eo-match[i].rm_so,
  21. &str[match[i].rm_so]);
  22. }
  23. return 0;
  24. }
Add Comment
Please, Sign In to add comment