[英]What is wrong with this boost c++ regex code?
#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;
}
我需要得到不允許的路徑/
從Disallow: /
什么是錯的我正則表達式?
string robotsfile = "User-Agent: *"
"Disallow: /";
上面的字符串文字被合並到“ User-Agent:* Disallow:/”中,沒有您可能認為的換行符。 由於您的正則表達式指出字符串必須以“ Disallow”詞開頭,因此不匹配。 邏輯上正確的代碼如下所示:
string robotsfile = "User-Agent: *\n"
"Disallow: /";
要么
string robotsfile = "User-Agent: *\nDisallow: /";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.