std::regex_match()冻结我的程序
std::regex_match() freezes my program
这是我的程序:
#include "stdafx.h"
#include <iostream>
#include <string>
#include <regex>
#include <windows.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string str = "<link rel="shortcut icon" href="http://joyvy.com/img/favicon.png" />";
regex expr("<link rel=+("|')+shortcut+(.*?("|'))+(.*?)href=("|')+(.*?)+("|')");
smatch matches;
cout << "start..." << endl;
regex_match(str, matches, expr);
cout << "this will not be printed";
}
这是我程序的输出:
start...
函数的std::regex_match()调用只是冻结了我的程序。经过2或3分钟后,它会出现错误:
Unhandled exception at at 0x7515B760 in regex.exe: Microsoft C++ exception: std::regex_error at memory location 0x001D9088.
那怎么了?
看起来您的正则表达式太复杂了,处理起来需要很长时间。这可能是因为你似乎不理解+
在正则表达式中的含义。你似乎相信它是用来串联或其他什么的。事实上,它的意思是"前一个元素重复了一次或多次",类似于*
,意思是"重复了零次或更多次"。去掉所有的优点,程序就会工作。
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 我的字符计数代码计算错误.为什么
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- cmake在我的项目中所需的所有静态库都不成功
- 为什么我的代码在输出中增加了93天
- 我的简单if-else语句是如何无法访问的代码
- 为什么我的for循环不能正确获取argv
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 0-1背包代码中的错误.我的代码中有什么错误
- 为什么我的输出在到达代码的这一部分时冻结?
- 我的程序结束后会冻结
- 为什么我的程序在字符串::插入()处冻结
- 使用XLib截屏会冻结我的计算机
- SRAND 导致我的程序冻结
- 我可以编写什么程序来冻结/挂起我的程序来测试看门狗计时器
- std::regex_match()冻结我的程序
- Qt事件后,长例程冻结了我的应用程序一段时间
- 内存取消分配冻结了我的程序
- 为什么我的程序在管道读取过程中冻结?