]>
Commit | Line | Data |
---|---|---|
c90a2db6 UD |
1 | #include <error.h> |
2 | #include <sys/types.h> | |
3 | #include <regex.h> | |
1e275b9e | 4 | #include <stdio.h> |
c90a2db6 UD |
5 | #include <stdlib.h> |
6 | ||
7 | int | |
8 | main (void) | |
9 | { | |
10 | regex_t re; | |
11 | regmatch_t ma[2]; | |
12 | int reerr; | |
13 | int res = 0; | |
14 | ||
15 | re_set_syntax (RE_DEBUG); | |
16 | reerr = regcomp (&re, "0*[0-9][0-9]", 0); | |
17 | if (reerr != 0) | |
18 | { | |
19 | char buf[100]; | |
20 | regerror (reerr, &re, buf, sizeof buf); | |
e9813cfb | 21 | error (EXIT_FAILURE, 0, "%s", buf); |
c90a2db6 UD |
22 | } |
23 | ||
24 | if (regexec (&re, "002", 2, ma, 0) != 0) | |
25 | { | |
cd61d12c | 26 | error (0, 0, "\"0*[0-9][0-9]\" does not match \"002\""); |
a2860282 | 27 | res = 1; |
c90a2db6 | 28 | } |
7f0d9e61 | 29 | puts ("Successful match with \"0*[0-9][0-9]\""); |
cd61d12c UD |
30 | |
31 | regfree (&re); | |
32 | ||
33 | reerr = regcomp (&re, "[0a]*[0-9][0-9]", 0); | |
34 | if (reerr != 0) | |
35 | { | |
36 | char buf[100]; | |
37 | regerror (reerr, &re, buf, sizeof buf); | |
e9813cfb | 38 | error (EXIT_FAILURE, 0, "%s", buf); |
cd61d12c UD |
39 | } |
40 | ||
41 | if (regexec (&re, "002", 2, ma, 0) != 0) | |
42 | { | |
43 | error (0, 0, "\"[0a]*[0-9][0-9]\" does not match \"002\""); | |
44 | res = 1; | |
45 | } | |
7f0d9e61 | 46 | puts ("Successful match with \"[0a]*[0-9][0-9]\""); |
cd61d12c UD |
47 | |
48 | regfree (&re); | |
c90a2db6 | 49 | |
a2860282 | 50 | return res; |
c90a2db6 | 51 | } |