使用C++正则表达式库中的regex_search
Using regex_search from the C++ regex library
regex_search函数的行为并不像预期的那样。
#include <iostream>
#include <regex>
#include <string>
using namespace std;
int main()
{
string str = "Hello world";
const regex rx("Hello");
cout << regex_search(str.begin(), str.end(), rx) << endl;
return 0;
}
输出为
0
怎么回事?
正如对该问题的评论中所指出的,C++标准库的旧实现还不支持C++11中的所有功能。当然,libc++是个例外,因为它最初是专门为C++11构建的。
根据这个错误报告,libstdc++中对<regex>
的支持仅在GCC的4.9版本中实现。您可以在libstdc++状态页上检查当前状态。
可以确认,您的示例适用于GCC 4.9,但在GCC 4.8中仍然失败。
相关文章:
- 此模式的C++RegEx
- QTableview Search
- LeetCode 1011.Binary Search,C++和Python的想法相同,但输出不同
- C++ std::regex 使用前瞻失败
- std::regex:匹配由数字和空格组成的字符串,并提取数字.如何?
- 二叉搜索树 - 实现"search"函数
- 使用 boost::regex 从目录中获取带有一些正则表达式的文件名称时出现意外输出
- 你能防止 std::regex 在无效表达式上抛出异常吗?
- 使用Regex解析cpp中的字符串并创建映射
- C++:如何用split查找单词?Regex
- 在VC2015U3上,std::regex比boost::regex慢得多
- 是否有更有效的方法来生成日期的REGEX字符串
- 在C++中使用带有regex的捕获组
- 将std::regex设置为静态的好主意吗
- 为什么Regex(c++)需要指数时间
- std::regex and dual ABI
- C++11 std::regex后备选项
- 以不同的方式替换每一项,regex c++
- 使用 boost::regex (c++) 比较两个正则表达式
- 如何理解boost::regex的哪一部分未能匹配/search