从html代码里提取字符编码

 

#include <iostream>
#include "regex"
using namespace std;
std::string str = R"( <HTML>< META HTTP - EQUIV = \"CONTENT-TYPE\" CONTENT=\"TEXT/HTML;CHARSET=UTF-8\">\r\n\t<META HTTP-EQUIV=\"X-UA-COMPATIBLE\" CONTENT=\"IE=EDGE\">)";
std::regex r(R"(<\s*META[^>]+/?>)");
std::smatch sm;
//通过正则表达式遍历meta标签
for (sregex_iterator it(str.begin(), str.end(), r), end; it != end; it++)
{

for (auto aa : *it)
cout << aa.str() << " ";
cout << endl;
}
//std::regex r(R"(<\s*META[^>]+CHARSET[^>]+/?>)"); 所有包含charset属性或内容的meta标签

获得以后剩下的任务就是字符串查找提取编码了

posted on 2017-08-02 13:04  孤山独剑  阅读(232)  评论(0编辑  收藏  举报

导航