【发布时间】:2013-11-17 04:44:02
【问题描述】:
我尝试使用 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 标准定义的语法。
【问题讨论】:
-
gcc.gnu.org - GCC 的正则表达式支持非常新。
-
我猜问题出在语法上。
-
clang 与 its own library 给出真,然后是假,与 boost.regex 相同。 GCC 4.8.2 不支持正则表达式,你需要 4.9。
-
GCC 4.9 之前的版本在语法上支持
<regex>,但在语义上不支持。
标签: c++ regex gcc c++11 gcc4.8