首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

linux下的C想使用正则.怎么操作

2012-04-01 
linux下的C想使用正则...如何操作?如题有高人回答不?[解决办法]像这样 ::$ cat 1.c gcc -o 1 1.c ./1/

linux下的C想使用正则...如何操作?
如题有高人回答不?

[解决办法]
像这样 ::

$ cat 1.c ; gcc -o 1 1.c ; ./1
/* 1.c */
# include <stdio.h>
#include <regex.h>

int main()
{
char line[1024] = " ";
regex_t re ;
regmatch_t rm[10];

freopen( __FILE__ , "r " , stdin );
regcomp( &re , "^[[:space:]]*#[[:space:]]*include[[:space:]]* <(.*)> [[:space:]]*$ " , REG_EXTE
NDED | REG_NEWLINE );
while( gets( line ) )
{
if( REG_OKAY == regexec( &re , line , 2 , rm , 0 ) )
{
printf( "match %s\n " , line );
line[rm[1].rm_eo] = 0;
printf( "file : %s\n " , line + rm[1].rm_so );
}
}
return 0;
}
/********************************************************/

match # include <stdio.h>
file : stdio.h
match #include <regex.h>
file : regex.h
[解决办法]
没有你也可以下个开源的正则库编译下啊 ...
linux/unix下都用几百年了, posix 标准定义了正则表达式...

热点排行