Strange results when using C++11 regexp with gcc 4.8.2 (but works with Boost regexp) [duplicate]

大兔子大兔子 提交于 2019-12-17 16:37:07

问题


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  (???)

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)

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.


回答1:


It's not supported in GCC 4.8.x. Check out the corresponding Bugzilla entry:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53631

Specifically: "Now regex is implemented. Should come with GCC 4.9 :)"



来源:https://stackoverflow.com/questions/20027305/strange-results-when-using-c11-regexp-with-gcc-4-8-2-but-works-with-boost-reg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!