8

我尝试使用 C++11 的正则表达式,但即使在微不足道的例子中也失败了。从外面看,似乎只比较字符串,例如:

std::regex_match(std::string{""}, std::regex{"a?"})   // false (???)
std::regex_match(std::string{"a?"}, std::regex{"a?"}) // true  (???)

相比之下,Boost 的正则表达式库的行为与我预期的一样:

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 库)。要么库坏了,要么我不理解 C++11 标准定义的语法。

4

1 回答 1

7

GCC 4.8.x 不支持它。查看相应的 Bugzilla 条目:

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

具体来说:“现在实现了正则表达式。应该带有 GCC 4.9 :)”

于 2013-11-17T05:36:17.350 回答