include
#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");
}
if i input http://www.google.co.in i am getting returned as www.google.com but if i input httpasd://www.google.co.in i am getting httpasd ..there should not be any match na y i am getting the match ???
^(?:http://)?([^\\/]+)(.*)$the ? at the end of
(?:http://)?means that bit is optionalthis
([^\\/]+)captures and matches anything that is not a \ or /this
(.*)captures everything else up to the end of the linePerhaps your after something more like
^(?:https?://)([^\\/]+)(.*)$might like to consider full URL syntax along the lines of
Then your heading for a regex more like