c++ - std::regex_match() freezes my program -


so here 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 not printed"; } 

and here output of program:

start... 

the std::regex_match() function call freezes program. after lapse of 2 or 3 minutes trows error:

unhandled exception @ at 0x7515b760 in regex.exe: microsoft c++ exception: std::regex_error @ memory location 0x001d9088. 

so what's wrong?

looks regular expression complex, , takes forever process. , reason don't seem understand + means in regular expression. seem believe it's used concatenation or something. in fact, means "the previous element repeated 1 or more times", similar * meaning "repeated 0 or more times". drop pluses, , program works.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -