qt 中使用正则表达式去除匹配到的内容

来源:互联网 发布:迪士尼影业 知乎 编辑:程序博客网 时间:2024/06/06 16:33
    string strMsg = "MainWindow::createMeasurePage(): dvctype=DvcMisc,cmd=WELCM,logonuser=adf";    QTextCodec * codec = QTextCodec::codecForName("UTF-8");    QString qstr = codec->toUnicode(strMsg.c_str(), strMsg.length());    QString strRx("^[a-zA-Z][a-zA-Z0-9_]*::[a-zA-Z][a-zA-Z0-9_]*\\(\\):\\s");    QRegExp rxlen(strRx);    int pos = rxlen.indexIn(qstr);    if (pos > -1) {        QString value = rxlen.cap(0); //        QString unit = rxlen.cap(1);  //        qDebug() << value << unit << pos <<"match over";    }    //*/   // QString strTmp = "MainWindow::createMeasurePage(): dvctype=DvcMisc,cmd=WELCM,logonuser=adf";    qstr.replace(rxlen, "");    qDebug() << qstr << "return" << endl;