2
0

regex.c 858 B

12345678910111213141516171819202122232425262728293031323334
  1. #include <regex.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include "test_helpers.h"
  5. int main(void) {
  6. regex_t regex;
  7. char error_buf[256];
  8. int error = regcomp(&regex, "h.llo \\(w.rld\\)", REG_ICASE);
  9. if (error) {
  10. regerror(error, &regex, error_buf, 255);
  11. error_buf[255] = 0;
  12. printf("regcomp error: %d = %s\n", error, error_buf);
  13. exit(EXIT_FAILURE);
  14. }
  15. regmatch_t matches[3] = {{0}};
  16. error = regexec(&regex, "Hey, how are you? Hello? Hallo Wurld??", 3, matches, 0);
  17. regfree(&regex);
  18. if (error) {
  19. regerror(error, &regex, error_buf, 255);
  20. printf("regexec error: %d = %s\n", error, error_buf);
  21. exit(EXIT_FAILURE);
  22. }
  23. for (int group = 0; group < 3; group += 1) {
  24. printf("Matching group: %d - %d\n", matches[group].rm_so, matches[group].rm_eo);
  25. }
  26. }