C++11 正则匹配
我正在 C++11(使用 gcc 4.7.2)中尝试一个相当简单的正则表达式匹配,但是我遇到了很多麻烦.尝试使用
I'm attempting a fairly simple regex match in C++11 (using gcc 4.7.2), but I'm having a large amount of trouble. Attempting to construct a pattern using
std::regex unquoted(R"regex(s*([^",]+)s*)regex");
导致构造函数抛出一个 std::regex_error
异常,代码为 std::regex_constants::error_escape
.几个在线正则表达式测试者对相同的表达式没有问题,我尝试使用不同的一些不同的语法选项无济于事.C++ 正则表达式语法有什么根本不同的地方我没有掌握?
causes the constructor to throw a std::regex_error
exception with the code std::regex_constants::error_escape
. Several regex testers online have no problem with the same expression, and I've tried using different some of the different syntax options to no avail. Is there something fundamentally different about the C++ regex syntax that I'm not grasping?
推荐答案
参见 gcc 的 stdc++11 实现状态页面 -- 自 gcc 4.8 起不支持正则表达式
See gcc's stdc++11 implementation status page -- regexes are not supported as of gcc 4.8
为后代正如评论中提到的,正则表达式库现在在 libstdc++
中,应该在 gcc 4.9 及更高版本中.
Edit for posterity: As mentioned in the comments, the regex library is now in libstdc++
and should be in gcc 4.9 and on.
相关文章