这个升压 c++ 有什么问题吗?正则表达式代码?
包括
#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: /
获取不允许的路径 /
我的正则表达式有什么问题?
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:(.*)quot;);
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??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
上面的字符串文字被合并到“User-Agent: *Disallow: /”中,并且没有您可能想到的换行符。由于您的正则表达式规定字符串必须以“Disallow”单词开头,因此它不匹配。逻辑上正确的代码将是这样的:
或者
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