.
[glibc/history.git] / posix / regexbug1.c
blob28640968d039d0342751ca5941a4ac540a9f2f0e
1 #include <error.h>
2 #include <sys/types.h>
3 #include <regex.h>
4 #include <stdio.h>
5 #include <stdlib.h>
7 int
8 main (void)
10 regex_t re;
11 regmatch_t ma[2];
12 int reerr;
13 int res = 0;
15 re_set_syntax (RE_DEBUG);
16 reerr = regcomp (&re, "0*[0-9][0-9]", 0);
17 if (reerr != 0)
19 char buf[100];
20 regerror (reerr, &re, buf, sizeof buf);
21 error (EXIT_FAILURE, 0, buf);
24 if (regexec (&re, "002", 2, ma, 0) != 0)
26 error (0, 0, "\"0*[0-9][0-9]\" does not match \"002\"");
27 res = 1;
29 puts ("Succesful match with \"0*[0-9][0-9]\"");
31 regfree (&re);
33 reerr = regcomp (&re, "[0a]*[0-9][0-9]", 0);
34 if (reerr != 0)
36 char buf[100];
37 regerror (reerr, &re, buf, sizeof buf);
38 error (EXIT_FAILURE, 0, buf);
41 if (regexec (&re, "002", 2, ma, 0) != 0)
43 error (0, 0, "\"[0a]*[0-9][0-9]\" does not match \"002\"");
44 res = 1;
46 puts ("Succesful match with \"[0a]*[0-9][0-9]\"");
48 regfree (&re);
50 return res;