Back to index

glibc  2.9
regexbug1.c
Go to the documentation of this file.
00001 #include <error.h>
00002 #include <sys/types.h>
00003 #include <regex.h>
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006 
00007 int
00008 main (void)
00009 {
00010   regex_t re;
00011   regmatch_t ma[2];
00012   int reerr;
00013   int res = 0;
00014 
00015   re_set_syntax (RE_DEBUG);
00016   reerr = regcomp (&re, "0*[0-9][0-9]", 0);
00017   if (reerr != 0)
00018     {
00019       char buf[100];
00020       regerror (reerr, &re, buf, sizeof buf);
00021       error (EXIT_FAILURE, 0, buf);
00022     }
00023 
00024   if (regexec (&re, "002", 2, ma, 0) != 0)
00025     {
00026       error (0, 0, "\"0*[0-9][0-9]\" does not match \"002\"");
00027       res = 1;
00028     }
00029   puts ("Succesful match with \"0*[0-9][0-9]\"");
00030 
00031   regfree (&re);
00032 
00033   reerr = regcomp (&re, "[0a]*[0-9][0-9]", 0);
00034   if (reerr != 0)
00035     {
00036       char buf[100];
00037       regerror (reerr, &re, buf, sizeof buf);
00038       error (EXIT_FAILURE, 0, buf);
00039     }
00040 
00041   if (regexec (&re, "002", 2, ma, 0) != 0)
00042     {
00043       error (0, 0, "\"[0a]*[0-9][0-9]\" does not match \"002\"");
00044       res = 1;
00045     }
00046   puts ("Succesful match with \"[0a]*[0-9][0-9]\"");
00047 
00048   regfree (&re);
00049 
00050   return res;
00051 }