包括
#include <algorithm>
#include<boost/algorithm/string.hpp>
#include<boost/regex.hpp>
using namespace std;
using namespace boost;
string _getBasehtttp(string url)
{
regex exrp("^(?:http://)?([^\\/]+)(.*)$");
match_results<string::const_iterator> what;
if(regex_search(url, what, exrp))
{
string base(what[1].first, what[1].second);
return base;
}
return "";
}
int main() {
cout << _getBasehtttp("httpasd://www.google.co.in");
}
如果我输入http://www.google.co.in
我正在返回www.google.com
但如果我输入httpasd://www.google.co.in
我得到httpasd
..there不应该有任何的比赛呐Ÿ我得到了比赛???最新错误与我的C + + boost正则表达式函数?
正则表达式u能告诉我,我怎么能说得对正则表达式 – raj 2010-09-03 20:56:01
@raj,这完全取决于_what_你想匹配,并且你想什么** **不匹配。我很高兴@Greg能够推测这一点(我从你的接受中推断出来),因为我的思维阅读能力有限;-)。 – 2010-09-03 21:28:10