ÕâÊÇCµÄÔ³ÌÐò
#include <stdio.h>
#include <regex.h>
int main(int argc, char** argv)
{
regex_t reg;
regmatch_t pm[10];
char *pattern;
char buf[50];
const size_t nmatch = 10;
pattern = argv[1];
int result = regcomp(®, pattern, REG_EXTENDED);
while( fgets(buf, sizeof(buf), stdin) )
{
int e = 0;
if ( e = strlen(buf) > 0 && buf[e-1] == '\n' )
buf[e-1] = 0;
result = regexec( ®, buf, nmatch, pm, REG_NOTBOL );
if ( result == REG_NOMATCH )
continue;
int i = 0;
for ( i = 0; i < nmatch && pm[i].rm_so != -1; ++i )
{
char c[50] ;
strncpy( c, buf + pm[i].rm_so, pm[i].rm_eo - pm[i].rm_so );
c[pm[i].rm_eo - pm[i].rm_so] = 0;
printf("%d,%d:%s\n", pm[i].rm_so, pm[i].rm_eo,c);
}
}
}
ÕâÊDzâÊÔÎļþÄÚÈÝ£º
µÄrqyy rqyy
Ò»ggll ggll
²»gii gii
ÊÇjghu jghu
ÁËbnh bnhÊÇjghu jghu
ÎÒtrnt trnt
Ëûwbn wbnÊÇjghu jghu
ÈËwwww wwww
µÍµãwqhk
µÍÁäwqhwÊÇjghu jghu
¶íµÒÆÖ˹wqia
¸«Ï÷wqie
µÍ³±wqifÊÇjghu jghu
µÍÍÝwqif
µÍÎÂwqij
µÍ³Áwqip
µÍÁÓwqit
ÑöÓ¾wqiy
ÄãÊÇwqjg
ÏñÊÇwqjg
º¬½ðÁ¿wqjg
±àÒëºóÖ´ÐÐ
bash-4.0$ ./reg "[a-y]*$" <aaa ûÓÐÊä³öÊý¾Ý
13,13:
13,13:
11,11:
13,13:
23,23:
13,13:
23,23:
13,13:
11,11:
23,23:
17,17:
11,11:
23,23:
11,11:
11,11:
11,11:
11,11:
11,11:
11,11:
11,11:
14,14:
bash-4.0$ ./reg "[a-y]*" <aaa
0,0:
0,0:
0,0:
0,0:
0,0:
0,0:
0,0:
0,0:
0,0:
0,0:
0,0:
0,0:
0,0:
0,0:
0,0:
0,0:
0,0:
0,0:
0,0:
0,0:
0,0:
bash-4.0$ ./reg "[a-y]" <aaa //Æ¥Åäµ½ÁËÒ»¸ö×Öĸ
3,4:r
3,4:g
3,4:g
3,4:j
3,4:b
3,4:t
3,4:w
3,4:w
6,7:w
6,7:w
12,13:w
6,7:w
6,7:w
6,7:w
6,7:w
6,7:w
6,7:w
6,7:w
6,7:w
6,7:w
9,10:w
bash-4.0$ ./reg "[a-y]{1,}" <aaa //Æ¥Åäµ½Á˽áβËĸö×Öĸ
3,7:rqyy
3,7:ggll
3,6:gii
3,7:jghu
3,6:bnh
3,7:trnt
3,6:wbn
3,7:wwww
6,10:wqhk
6,10:wqhw
12,16:wqia
6,10:wqie
6,10:wqif
6,10:wqif
6,10:wqij
6,10:wq
¼ÙÉèÎÒÃÇʹÓÃmysql_real_queryÖ´ÐÐÁËÒ»ÌõsqlÓï¾äÖ®ºó£¬·µ»ØֵΪ·Ç0Öµ£¬´ó¼Ò¶¼ÖªµÀÕâÊÇÕâÌõÓï¾äÖ´Ðгö´í£¬µ«ÊÇÎÒÃÇÏë
Á˽âµØ¸üÏêϸµãµÄ»°£¬¾¿¾¹ÊÇʲôÔÒòµ¼ÖÂÁËÕâ¸ö´íÎóÄØ£¿Õâʱºò¾ÍµÃÓÃÉÏmysqlÌṩµÄÁíÍâÒ»¸öAPI£ºmysql_errno¡£
mysql_errno»áÌṩ×î½üÒ»´Îµ÷ÓõÄC API³ö´íµÄÐÅÏ¢£¨²»¼ûµÃÿ¸öAPI¶¼»á¶ÔÕâ¸öerrno½øÐÐÉèÖ ......