fork download
  1. #include <stdio.h>
  2. #include <regex.h>
  3. #include <stdlib.h>
  4.  
  5. #define STRING "Abcde19:36zxc. Aasd 01:12 yyy. Qqq 24:45=0.53. Takie dela. 11:17 00:00, odnako." // пример строки
  6. #define PATTERN "(([0-1][0-9])|(2[0-3])):([0-5][0-9])" // регулярное выражение для времени
  7.  
  8. int main() {
  9. char * s = STRING;
  10. regex_t * preg = (regex_t*)malloc(sizeof(regex_t));
  11. regcomp(preg, PATTERN, REG_EXTENDED);
  12.  
  13. int nmatch = 16; // я так полагаю, это максимальное число ищущихся совпадений
  14. regmatch_t * pmatch = (regmatch_t *)malloc(nmatch * sizeof(regmatch_t));
  15. regexec(preg, s, nmatch, pmatch, 0);
  16.  
  17. for (int i = 0; i < nmatch; ++i) {
  18. for (int j = pmatch[i].rm_so; j < pmatch[i].rm_eo; ++j) {
  19. printf("%c", s[j]);
  20. }
  21. printf("\n");
  22. }
  23. }
  24.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
19:36
19
19

36