从html代码里提取字符编码

#include <iostream>
#include "regex"
using namespace std;
std::string str = R"( <HTML>< META HTTP - EQUIV = "CONTENT-TYPE" CONTENT="TEXT/HTML;CHARSET=UTF-8"> <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标签

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

原文地址:https://www.cnblogs.com/gushandujian/p/7273359.html