Home > Software engineering >  C regular match failure
C regular match failure

Time:10-07

Me grasp the content of the other sites to come over, want to use regular match out what I want, but how to how to write, regex_match returned are false

The scraping of the page code
 cstrings httpGet (cstrings url) {
USES_CONVERSION;
CInternetSession s;
CHttpFile * fileGet;
Try {
FileGet=(CHttpFile *) s.O penURL (url);
DWORD status;
FileGet - & gt; QueryInfoStatusCode (status);
//cout & lt; {} the catch (CInternetException * ex)
FileGet=NULL;
The ex - & gt; M_dwError;
The ex - & gt; The Delete ();
S.C lose ();
Cout & lt; <"Abnormal" HTTP requests;
Return L "";
}
Cstrings strHtml=_T (" ");
Char sRecived [1024].
While (fileGet - & gt; ReadString (LPTSTR sRecived, 1024).=NULL) {
StrHtml +=sRecived;
}
Return strHtml;
Char * pChar=W2A (strHtml. GetBuffer ());
Cstrings gb2312String=ConvertUTF8toGB2312 (pChar, strlen (pChar));

FileGet - & gt; Close ();
The delete fileGet;
S.C lose ();

Return gb2312String;
}


The matching test
 cstrings response=httpGet (L "http://www.163.com/"); 
A string of text=cstr2str (response);
Cout & lt; Const regex reg (" * ");//what doesn't work can regular
Cout & lt; While (true);
return 0;


Pray god to help

CodePudding user response:

You VS the regex is effective, VS low version of the regex may no implementation,

CodePudding user response:

refer to the original poster aspwebchh response:
me grasp the content of the other sites to come over, want to use regular match out of what I want, but how to how to write, regex_match returned are false

The scraping of the page code
 cstrings httpGet (cstrings url) {
USES_CONVERSION;
CInternetSession s;
CHttpFile * fileGet;
Try {
FileGet=(CHttpFile *) s.O penURL (url);
DWORD status;
FileGet - & gt; QueryInfoStatusCode (status);
//cout & lt; {} the catch (CInternetException * ex)
FileGet=NULL;
The ex - & gt; M_dwError;
The ex - & gt; The Delete ();
S.C lose ();
Cout & lt; <"Abnormal" HTTP requests;
Return L "";
}
Cstrings strHtml=_T (" ");
Char sRecived [1024].
While (fileGet - & gt; ReadString (LPTSTR sRecived, 1024).=NULL) {
StrHtml +=sRecived;
}
Return strHtml;
Char * pChar=W2A (strHtml. GetBuffer ());
Cstrings gb2312String=ConvertUTF8toGB2312 (pChar, strlen (pChar));

FileGet - & gt; Close ();
The delete fileGet;
S.C lose ();

Return gb2312String;
}


The matching test
 cstrings response=httpGet (L "http://www.163.com/"); 
A string of text=cstr2str (response);
Cout & lt; Const regex reg (" * ");//what doesn't work can regular
Cout & lt; While (true);
return 0;


Pray god help


Visual studio 2015

CodePudding user response:

reference 1st floor oyljerry response:
you VS the regex is effective, VS low version of the regex may no implementation,

The vs2015

CodePudding user response:

Regex_match request string matching the entire story from beginning to end, "*" can't match a newline, and there must be a newline characters in HTML text, so the match fails,
To search matching substring in the HTML, all you need is regex_search rather than regex_match

CodePudding user response:

It is recommended to use regtest software,

CodePudding user response:

Write their own filter function
  • Related