这是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);
}
}
}
这是测试文件内容:
的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
根据工作环境的需求,需要掌握Linux/Unix环境下进行软件安装维护以及相关配置等技能。这里将我的使用心得记录下来跟大家分享一下。以安装数据库为例进行讲解(注:以上安装均以源代码方式进行安装)。以下使用的Linux系统是安装在虚拟机上的,并且linux系统是linux enterprise 5。
&nb ......