#include <stdio.h>
#include <regex.h>
int
regex_match (char *pattern, const char *string)
{
int status;
regex_t re;
status = regcomp (&re, pattern, REG_EXTENDED|REG_NOSUB);
if (status != 0)
{
return (0);
}
status = regexec (&re, string, (size_t) 0, NULL, 0);
if (status != 0)
{
regfree (&re);
return (0);
}
regfree (&re);
return (1);
}
int
main (void)
{
char *string = "Ciao amore mio";
char *re = "iao";
if (regex_match (re, string))
{
printf ("Il modello \"%s\" trova corrispondenza ", re);
printf ("nella stringa \"%s\"\n", string
); }
else
{
printf ("Il modello \"%s\" ", re
); printf ("NON trova corrispondenza "); printf ("nella stringa \"%s\"\n", string
); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxyZWdleC5oPgoKaW50CnJlZ2V4X21hdGNoIChjaGFyICpwYXR0ZXJuLCBjb25zdCBjaGFyICpzdHJpbmcpCnsKICAgIGludCAgICAgICBzdGF0dXM7CiAgICByZWdleF90ICAgcmU7CiAgICBzdGF0dXMgPSByZWdjb21wICgmcmUsIHBhdHRlcm4sIFJFR19FWFRFTkRFRHxSRUdfTk9TVUIpOwogICAgaWYgKHN0YXR1cyAhPSAwKQogICAgICB7CiAgICAgICAgcmV0dXJuICgwKTsKICAgICAgfQogICAgc3RhdHVzID0gcmVnZXhlYyAoJnJlLCBzdHJpbmcsIChzaXplX3QpIDAsIE5VTEwsIDApOwogICAgaWYgKHN0YXR1cyAhPSAwKQogICAgICB7CiAgICAgICAgcmVnZnJlZSAoJnJlKTsKICAgICAgICByZXR1cm4gKDApOwogICAgICB9CiAgICByZWdmcmVlICgmcmUpOwogICAgcmV0dXJuICgxKTsKfQoKaW50Cm1haW4gKHZvaWQpCnsKICAgIGNoYXIgKnN0cmluZyAgICAgICA9ICJDaWFvIGFtb3JlIG1pbyI7CiAgICBjaGFyICpyZSAgICAgICAgICAgPSAiaWFvIjsKCiAgICBpZiAocmVnZXhfbWF0Y2ggKHJlLCBzdHJpbmcpKQogICAgICB7CiAgICAgICAgcHJpbnRmICgiSWwgbW9kZWxsbyBcIiVzXCIgdHJvdmEgY29ycmlzcG9uZGVuemEgIiwKICAgICAgICAgICAgICAgIHJlKTsKICAgICAgICBwcmludGYgKCJuZWxsYSBzdHJpbmdhIFwiJXNcIlxuIiwgc3RyaW5nKTsKICAgICAgfQogICAgZWxzZQogICAgICB7CiAgICAgICAgcHJpbnRmICgiSWwgbW9kZWxsbyBcIiVzXCIgIiwgcmUpOwogICAgICAgIHByaW50ZiAoIk5PTiB0cm92YSBjb3JyaXNwb25kZW56YSAiKTsKICAgICAgICBwcmludGYgKCJuZWxsYSBzdHJpbmdhIFwiJXNcIlxuIiwgc3RyaW5nKTsKICAgICAgfQogICAgcmV0dXJuIDA7Cn0=