(root)/
glibc-2.38/
posix/
regexbug1.c
       1  #include <error.h>
       2  #include <sys/types.h>
       3  #include <regex.h>
       4  #include <stdio.h>
       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);
      21        error (EXIT_FAILURE, 0, "%s", buf);
      22      }
      23  
      24    if (regexec (&re, "002", 2, ma, 0) != 0)
      25      {
      26        error (0, 0, "\"0*[0-9][0-9]\" does not match \"002\"");
      27        res = 1;
      28      }
      29    puts ("Successful match with \"0*[0-9][0-9]\"");
      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);
      38        error (EXIT_FAILURE, 0, "%s", buf);
      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      }
      46    puts ("Successful match with \"[0a]*[0-9][0-9]\"");
      47  
      48    regfree (&re);
      49  
      50    return res;
      51  }