C ++ 11正则表达式匹配 [英] C++11 Regex Matching

查看:270
本文介绍了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 。几个regex测试者在线对同一个表达式没有问题,我已经尝试使用不同的一些不同的语法选项没有效果。有没有一些根本不同的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

编辑后代:正如注释中提到的,regex库现在在 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正则表达式匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆