工作中需要用到C++中的正则表达式,所以研究了以上三种正则表达式。1、Cregex/*xingming*time:2012年10月19日15:51:53*for:testregex**/#include#include#include#include#include#includeusingnamespacestd;constinttimes=1000000;intmain(intargc,char**argv){字符模式[512]="财经\.sina\.cn|stock1\.sina\.cn|3g\.sina\.com\.cn.*(channel=finance|_finance$|ch=stock|/stock/)|dp.sina.cn/.*ch=9&";constsize_tnmatch=10;regmatch_tpm[10];诠释Z;regex_treg;charlbuf[256]="设置",rbuf[256];charbuf[3][256]={"finance.sina.cn/google.com/baidu.com.google.sina.cndddddddddddddddddddddda.sdfasdfeoasdfnahsfonadsdf","3g.com.sina.cn.google.com.dddddddddddddddddddddddddddddddddddddddddddddddddddddbaidu.com.sina.egooooooooo","http://3g.sina.com.cn/google.baiduchannel=financegogo.sjdfaposif;lasdjf.asdofjas;dfjaiel.sdfaosidfj"};printf("输入字符串:\n");timevalend,start;gettimeofday(&start,NULL);regcomp(®,pattern,REG_EXTENDED|REG_NOSUB);for(inti=0;i#include#include#includeusingnamespacestd;intmain(intargc,char**argv){正则表达式模式("[[:digit:]]",regex_constants::extended);printf("输入字符串:\n");字符串缓冲区;while(cin>>buf){printf("*******\n%s\n********\n",buf.c_str());if(buf=="quit"){printf("刚刚退出!\n");休息;}match_results结果;printf("现在运行比较!'%s'\n",buf.c_str());boolvalid=regex_match(buf,result,pattern);printf("现在比较!'%s'\n",buf.c_str());if(!valid)printf("不匹配!\n");否则printf("确定\n");}return0;}C++我真的不想谈了。测试时,字符匹配时,可以匹配'a',也可以匹配a+,[[:w:]]也可以匹配任意字符,但是[[:w:]]+只能匹配一个字符.+号似乎不起作用,所以我干脆放弃了这个很棒的C++正则表达式。如果有人知道我哪里错了,非常感谢。告诉我,谢谢。3、boostregex/*xingming写的*for:testboostregex*time:2012年10月23日11:35:33**/#include#include#include#include"boost/regex.hpp"usingnamespacestd;usingnamespaceboost;constinttimes=10000000;intmain(){regexpattern("finance\\.sina\\.cn|stock1\\.sina\\.cn|3g\\.sina\\.com\\.cn.*(channel=finance|_finance$|ch=stock|/stock/)|dp\\.sina\\.cn/.*ch=9&");cout<<"输入字符串:"<finance\.sina\.cn|stock1\.sina\.cn|3g\.sina\.com\.cn.*(?:channel=finance|_finance$|ch=stock|/stock/)|dp.sina.cn/.*ch=9&)",RegexOptions.Compiled);string[]str=newstring[]{@"finance.sina.cn/google.com/baidu.com.google.sina.cn",@"3g.com.sina.cn.google.com.baidu.com.sina.egooooooooo",@"http://3g.sina.com.cn/google.baiduchannel=financegogo"};int=0;日期时间开始=DateTime.Now;for(inti=0;i