language: C++ 4.7.2 (gcc-4.7.2)
date: 444 days 18 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <sys/types.h>
#include <regex.h>
#include <stdio.h>
 
int main(int argc, char *argv[]){
        regex_t regex;
        int reti;
        char msgbuf[100];
                char inputStr2[100]="12:34:04";
                char inputStr[100]="12:34";
 
/* Compile regular expression */
        reti = regcomp(&regex,"^\\(\\(\\([01]?[0-9]|2[0-3]\\):\\)?\\([0-5]?[0-9]\\):\\)?\\([0-5]?[0-9]\\)$"
, 0);
        if( reti ){
                fprintf(stderr, "Could not compile regex\n");
                }
 
/* Execute regular expression */
           printf("%s is the string\n",inputStr);
        reti = regexec(&regex, inputStr, 0, NULL, 0);
        if( !reti ){
                puts("Match");
        }
        else if( reti == REG_NOMATCH ){
                puts("No match");
        }
        else{
                regerror(reti, &regex, msgbuf, sizeof(msgbuf));
                fprintf(stderr, "Regex match failed: %s\n", msgbuf);
        }
         printf("%s is the string\n",inputStr2);
        reti = regexec(&regex, inputStr2, 0, NULL, 0);
        if( !reti ){
                puts("Match");
        }
        else if( reti == REG_NOMATCH ){
                puts("No match");
        }
        else{
                regerror(reti, &regex, msgbuf, sizeof(msgbuf));
                fprintf(stderr, "Regex match failed: %s\n", msgbuf);
        }
/* Free compiled regular expression if you want to use the regex_t again */
        regfree(&regex);
 
        return 0;
}