std::string string("0");
std::regex pattern("^0$",std::regex_constants::extended);
bool match(std::regex_match(string,pattern));
我相信 ^
和 $
必须分别匹配 BOL 和 EOL。因此 match
应该是 true
但实际上是 false
。我错过了什么吗?
最佳答案
libstdc++ 没有完全支持正则表达式(你可以查看 here )。 我试图用 clang 3.2 和 libc++-3.2 编译这段代码,结果是“真”。使用 libc++,或者 boost。
特别是libstdc++正则表达式实现状态
8 Regular expressions
28.1 General N
28.2 Definitions N
28.3 Requirements N
28.4 Header <regex> synopsis N
28.5 Namespace std::regex_constants Y
28.6 Class regex_error Y
28.7 Class template regex_traits Partial
28.8 Class template basic_regex Partial
28.9 Class template sub_match Partial
28.10 Class template match_results Partial
28.11 Regular expression algorithms N
28.12 Regular expression Iterators N
28.13 Modified ECMAScript regular expression grammar N
关于c++ - 使用 std::regex 匹配 BOL 和 EOL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18571131/