include
#include <fstream>
#include <string>
#include<string>
#include<boost/algorithm/string.hpp>
#include<boost/regex.hpp>
#include <boost/algorithm/string/trim.hpp>
using namespace std;
using namespace boost;
int main() {
string robotsfile="User-Agent: *"
"Disallow: /";
regex exrp( "^Disallow:(.*)$");
match_results<string::const_iterator> what;
if( regex_search( robotsfile, what, exrp ) )
{
string s( what[1].first, what[1].second );
cout<< s;
}
return 0;
}
i need to get the disallowed path / from Disallow: / what is wrong with my regex??
The string literals above are merged into “User-Agent: *Disallow: /” and there is no newline as you might have thought. Since your regular expression states that string must start with “Disallow” word, it does not match. The logically correct code would be something like this:
or