C++正则表达式匹配

来源:互联网 发布:ly是哪个国家的域名 编辑:程序博客网 时间:2024/04/27 20:26

例子:匹配 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>");
1 0
原创粉丝点击