我尝试使用 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 标准定义的语法。