c++ - 使用 std::regex 匹配 BOL 和 EOL

标签 c++ regex gcc boost std

std::string string("0");
std::regex pattern("^0$",std::regex_constants::extended);
bool match(std::regex_match(string,pattern));

我相信 ^$ 必须分别匹配 BOL 和 EOL。因此 match 应该是 true 但实际上是 false。我错过了什么吗?


gcc-4.8.1 live demo .

最佳答案

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/

相关文章:

c++ - 未调用模板成员的重载构造函数

c++ - Eclipse Cdt Indexer - 如何定位语法错误和未解析的名称

regex - 搜索并替换为正则表达式 webuilder

regex - 在 Linux 中查找具有匹配模式的文件

c - bash 无法执行可执行文件

c - 在非标准位置构建 gcc-4.3.4 时遇到问题

c++ - 未定义类型的无效使用 'struct PelephonePH'

c++ - DLL 中的实例化类在 QT 中的 LoadLibrary 中抛出 127 错误

c++ - Boost 库不使用 G++ 在 Netbeans 中编译

c++ - 命名空间与包含的类同名,gcc 可以,clang 不行