boost::regex

常见用法:

boost::regex express;

regex_match(str,express);  bool

smatch what;

cmatch what;

typedef match_results<const char*> cmatch;
typedef match_results<std::string::const_iterator> smatch;

regex_search(str,what,express);bool

what[0];

what[1];

regex_replace(str,express,kongge);

 

①匹配全串存在多个结果的情况下

主要针对string

boost::sregex_iterator ite(str.begin(), str.end(), express);
boost::sregex_iterator endite;
while (ite != endite)
{
cout<<*ite<<endl;
ite++;
}

char *p = "www.baidu.com---dffsfdsf--f-ff www.google.comddfdsffd";

boost::regex exp("\\w{3}\\.(\\w+\\.)+(net|com|cn)");

char *tmp = p;

cmath what;

while(boost::regex_search(tmp, what, exp))

{

  cout<<what[0]<<endl;

  tmp = what[0].second;

}

③可以通过const *p = s.c_str();

 

 

const_reference operator[](int n) const : 返回一个sub_match引用,当n=0时返回[first,last)的匹配结果,当0<n<=size时,返回对应元组的匹配结果,

当n>size时返回一个matched值为假的sub_match结构,元组按照左边括号的顺序和sub_match相对应,从1开始

 一篇写得不错的博文

 http://www.cnblogs.com/hucn/archive/2011/05/09/2041490.html

 

boost::regex iterator

http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/ref/regex_iterator.html

转载于:https://www.cnblogs.com/coderecord/p/4915578.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值