1#include <error.h>
2#include <sys/types.h>
3#include <regex.h>
4#include <stdio.h>
5#include <stdlib.h>
6
7int
8main (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 (preg: &re, pattern: "0*[0-9][0-9]", cflags: 0);
17 if (reerr != 0)
18 {
19 char buf[100];
20 regerror (errcode: reerr, preg: &re, errbuf: buf, errbuf_size: sizeof buf);
21 error (EXIT_FAILURE, errnum: 0, format: "%s", buf);
22 }
23
24 if (regexec (preg: &re, String: "002", nmatch: 2, pmatch: ma, eflags: 0) != 0)
25 {
26 error (status: 0, errnum: 0, format: "\"0*[0-9][0-9]\" does not match \"002\"");
27 res = 1;
28 }
29 puts (s: "Succesful match with \"0*[0-9][0-9]\"");
30
31 regfree (preg: &re);
32
33 reerr = regcomp (preg: &re, pattern: "[0a]*[0-9][0-9]", cflags: 0);
34 if (reerr != 0)
35 {
36 char buf[100];
37 regerror (errcode: reerr, preg: &re, errbuf: buf, errbuf_size: sizeof buf);
38 error (EXIT_FAILURE, errnum: 0, format: "%s", buf);
39 }
40
41 if (regexec (preg: &re, String: "002", nmatch: 2, pmatch: ma, eflags: 0) != 0)
42 {
43 error (status: 0, errnum: 0, format: "\"[0a]*[0-9][0-9]\" does not match \"002\"");
44 res = 1;
45 }
46 puts (s: "Succesful match with \"[0a]*[0-9][0-9]\"");
47
48 regfree (preg: &re);
49
50 return res;
51}
52

source code of glibc/posix/regexbug1.c