fork download
  1. #include <stdio.h>
  2. #include <regex.h>
  3.  
  4. static const char string[] = "Abcde19:36zxc. Aasd 01:12 yyy. Qqq 24:45=0.53. Takie dela. 11:17 00:00, odnako."; // пример строки
  5. static const char pattern[] = "(([0-1][0-9])|(2[0-3])):([0-5][0-9])"; // регулярное выражение для времени
  6.  
  7. int main(void)
  8. {
  9. regex_t preg;
  10. regcomp(&preg, pattern, REG_EXTENDED);
  11. regmatch_t m;
  12. for (const char *p = string; !regexec(&preg, p, 1, &m, 0); p += m.rm_eo) {
  13. printf("%.*s\n", m.rm_eo - m.rm_so, p + m.rm_so);
  14. }
  15. regfree(&preg);
  16. return 0;
  17. }
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
19:36
01:12
11:17
00:00