例子:匹配 room_id=13549846
QRegExp使用
QString getData = curlSimple.GetSimple(url);
QDBG << getData;
QRegExp rx("room_id=[\\d]{1,15}");
rx.indexIn(getData);
QString roomIDstr = rx.cap().remove("room_id=").remove("\"");
QDBG << roomIDstr;
std::regex使用
inline QString regexFrom(QString data, QString pnPattern)
{
std::string strData = data.toStdString();
std::regex pnR(pnPattern.toStdString());
for (std::sregex_iterator it(strData.begin(), strData.end(), pnR), end;
it != end;
++it)
{
return QString::fromStdString(it->str(1));
}
return "";
}
//匹配<span class=\"red\">(.*)</span>
QString URLcode = curl.GetSimple(QString::fromStdString(strUrl));
QDBG << QString::fromStdString(URLcode);
QDBG << regexFrom(URLcode,"<span class=\"red\">(.*)</span>");