当前位置: 技术问答>linux和unix
aix下c的模式匹配(常规表达式)问题,急!!!!
来源: 互联网 发布时间:2015-03-14
本文导语: aix下c的模式匹配(常规表达式)问题,急!!!! #include #include #include #define SUBSLEN 10 #define EBUFLEN 128 /* error buffer length */ #define BUFLEN 1024 /* matched buffer length */ int main (int argc, char **argv) { /*F...
aix下c的模式匹配(常规表达式)问题,急!!!!
#include
#include
#include
#define SUBSLEN 10
#define EBUFLEN 128 /* error buffer length */
#define BUFLEN 1024 /* matched buffer length */
int main (int argc, char **argv)
{
/*FILE *fp; */
size_t len; /* store error message length */
regex_t re; /* store compilned regular expression */
regmatch_t subs[SUBSLEN]; /* store matched string position */
char matched[BUFLEN]; /* store matched strings */
char errbuf[EBUFLEN]; /* store error message */
int err, i;
char string[] = "AAAAabaaabdCd123123 11(123){12}{12} Part 6 of 6";
/*char pattern[] = "(\([0-9]+\))(\{[0-9]+\})";*/
char pattern[] = "Part ([0-9]*) of \1";
printf ("String : %sn", string);
printf ("Pattern: "%s"n", pattern);
/* compile regular expression */
err = regcomp (&re, pattern, REG_EXTENDED);
if (err)
{
len = regerror (err, &re, errbuf, sizeof (errbuf));
printf ("error: regcomp: %sn", errbuf);
exit (1);
}
printf ("Total has subexpression: %dn", re.re_nsub);
/* execute pattern match */
err = regexec (&re, string, (size_t)SUBSLEN, subs, 0);
if (err == REG_NOMATCH)
{
printf ("Sorry, no match ...n");
regfree (&re);
exit (0);
} else if (err)
{
len = regerror (err, &re, errbuf, sizeof (errbuf));
printf ("error: regexec: %sn", errbuf);
exit (1);
}
/* if no REG_NOMATCH and no error, then pattern matched */
printf ("nOK, has matched ...nn");
for (i = 0; i
#include
#include
#include
#define SUBSLEN 10
#define EBUFLEN 128 /* error buffer length */
#define BUFLEN 1024 /* matched buffer length */
int main (int argc, char **argv)
{
/*FILE *fp; */
size_t len; /* store error message length */
regex_t re; /* store compilned regular expression */
regmatch_t subs[SUBSLEN]; /* store matched string position */
char matched[BUFLEN]; /* store matched strings */
char errbuf[EBUFLEN]; /* store error message */
int err, i;
char string[] = "AAAAabaaabdCd123123 11(123){12}{12} Part 6 of 6";
/*char pattern[] = "(\([0-9]+\))(\{[0-9]+\})";*/
char pattern[] = "Part ([0-9]*) of \1";
printf ("String : %sn", string);
printf ("Pattern: "%s"n", pattern);
/* compile regular expression */
err = regcomp (&re, pattern, REG_EXTENDED);
if (err)
{
len = regerror (err, &re, errbuf, sizeof (errbuf));
printf ("error: regcomp: %sn", errbuf);
exit (1);
}
printf ("Total has subexpression: %dn", re.re_nsub);
/* execute pattern match */
err = regexec (&re, string, (size_t)SUBSLEN, subs, 0);
if (err == REG_NOMATCH)
{
printf ("Sorry, no match ...n");
regfree (&re);
exit (0);
} else if (err)
{
len = regerror (err, &re, errbuf, sizeof (errbuf));
printf ("error: regexec: %sn", errbuf);
exit (1);
}
/* if no REG_NOMATCH and no error, then pattern matched */
printf ("nOK, has matched ...nn");
for (i = 0; i
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!