奇怪的结果当使用C ++ 11 regexp与gcc 4.8.2(但适用于Boost regexp) [英] Strange results when using C++11 regexp with gcc 4.8.2 (but works with Boost regexp)
问题描述
我试图使用C ++ 11的正则表达式,但失败,甚至在一个小例子。从外部,似乎只比较字符串,例如:
I tried to use C++11's regular expression but failed even in trivial examples. From the outside, it seems to only compare the strings, for example:
std::regex_match(std::string{""}, std::regex{"a?"}) // false (???)
std::regex_match(std::string{"a?"}, std::regex{"a?"}) // true (???)
相反,Boost的regexp库将会有:
In contrast, the Boost's regexp library behaves as I would have expected:
boost::regex_match(std::string{""}, boost::regex{"a?"}) // true (OK)
boost::regex_match(std::string{"a?"}, boost::regex{"a?"}) // false (OK)
我使用GCC 4.8.2和clang 3.4(也使用GCC的STL库)测试。
I tested with GCC 4.8.2 and clang 3.4 (also using GCC's STL library). Either the library is broken, or I do not understand the syntax defined by the C++11 standard.
推荐答案
它不支持在GCC 4.8.x.查看相应的Bugzilla条目:
It's not supported in GCC 4.8.x. Check out the corresponding Bugzilla entry:
具体来说:现在正规表达式已经实现了,应该和GCC 4.9 :)
Specifically: "Now regex is implemented. Should come with GCC 4.9 :)"
这篇关于奇怪的结果当使用C ++ 11 regexp与gcc 4.8.2(但适用于Boost regexp)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!