表达性>>=运算符
我正在尝试 Boost Xpressive,但在执行以下代码片段时遇到了问题。
#include <iostream>
#include <string>
#include <boost/xpressive/xpressive.hpp>
using namespace std;
using namespace boost::xpressive;
int main()
{
string s("123");
sregex rex = _d;
rex >>= _d;
smatch what;
regex_search(s, what, rex);
cout << "Match: " << what[0] << endl;
return 0;
}
运行该程序的结果是 1
的匹配,而不是预期的 12
。 sregex::operator>>=
是否具有不同的含义/使用我直观地假设的内容?我期望这会产生一个类似于 _d >>> 的
。sregex
。 _d
I am toying around with Boost Xpressive and am having trouble with the following snippet
#include <iostream>
#include <string>
#include <boost/xpressive/xpressive.hpp>
using namespace std;
using namespace boost::xpressive;
int main()
{
string s("123");
sregex rex = _d;
rex >>= _d;
smatch what;
regex_search(s, what, rex);
cout << "Match: " << what[0] << endl;
return 0;
}
The result of running this program is a match of 1
as opposed to the expected 12
. Does the sregex::operator>>=
have a different meaning/use what I intuitively assumed? I was expecting this to yield an sregex
similar to _d >> _d
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Xpressive 不支持 >>= 运算符。这段代码能够编译的事实可以被认为是一个错误。尝试:
但是,像这样零散地构建正则表达式将使正则表达式表现不佳。
Xpressive doesn't support the >>= operator. The fact that this code compiles at all could be considered a bug. Try:
However, building up a regex piecemeal like this will make the regex perform poorly.