C++11 Regex Matching(C++11 正则匹配)
问题描述
我正在 C++11(使用 gcc 4.7.2)中尝试一个相当简单的正则表达式匹配,但是我遇到了很多麻烦.尝试使用
I'm attempting a fairly simple regex match in C++11 (using gcc 4.7.2), but I'm having a large amount of trouble. Attempting to construct a pattern using
std::regex unquoted(R"regex(s*([^",]+)s*)regex");
导致构造函数抛出一个 std::regex_error 异常,代码为 std::regex_constants::error_escape.几个在线正则表达式测试者对相同的表达式没有问题,我尝试使用不同的一些不同的语法选项无济于事.C++ 正则表达式语法有什么根本不同的地方我没有掌握?
causes the constructor to throw a std::regex_error exception with the code std::regex_constants::error_escape. Several regex testers online have no problem with the same expression, and I've tried using different some of the different syntax options to no avail. Is there something fundamentally different about the C++ regex syntax that I'm not grasping?
推荐答案
参见 gcc 的 stdc++11 实现状态页面 -- 自 gcc 4.8 起不支持正则表达式
See gcc's stdc++11 implementation status page -- regexes are not supported as of gcc 4.8
为后代正如评论中提到的,正则表达式库现在在 libstdc++ 中,应该在 gcc 4.9 及更高版本中.
Edit for posterity: As mentioned in the comments, the regex library is now in libstdc++ and should be in gcc 4.9 and on.
这篇关于C++11 正则匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++11 正则匹配
基础教程推荐
- 初始化列表*参数*评估顺序 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- CString 到 char* 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
