c++之regex的应用

1、编译器:vs2003

2、语言:C++

3、正则表达式库:boost

4、程序要求:

     对于土豆网的一个视频页面地址(eg:http://www.tudou.com/playlist/p/a67087i94457134.html),能够提取出来vid,即94457134

5、程序代码:

string s="input the web site:\n";
	cout<<s<<endl;
	string url;
	getline(cin,url);
	cout<<"you enter the string is :"<<url<<endl;
	string regstr="^.+?/p/a\\d+i(\\d+)\\.html";
           regex expre(regstr);
	smatch what;

	if(regex_match(url,what,expre))
	{
	  cout<<"match"<<endl;
	  for(int i=0;i<what.size();i++)
	    cout<<"str:"<<what[i].str()<<endl;
	}
	else
	{
	   cout<<"Not match"<<endl;
	}

 注意一点:对于在c++中使用正则表达式来说,对于反斜杠\,必须在前面在加一个反斜杠,例如:如果想表达C:\temp,则正则表达式要写成C:\\temp,进一步在c++中要写成C:\\\\temp。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值