QString str = QString::fromLocal8Bit("<img id=\"app-logo\" alt=\"???????APP\" src=\"http://abc/setup/ico.jpg\" >") + QString::fromLocal8Bit("<img id=\"app-logo\" alt=\"???????APP\" src=\"http://www.abc/setup/ico3.jpg\" >"); QRegularExpression rx(".*src=\"(?<Url>.*)\".*"); QStringList strList = str.split("img"); foreach(QString s,strList) { QRegularExpressionMatch rm = rx.match(s); if (rm.hasMatch()) { qDebug() << rm.captured("Url"); } }
http://abc/setup/ico.jpg
http://www.abc/setup/ico3.jpg
匹配以.mp3或.wma结尾的文件
foreach(QUrl url,urlList) { QString file_name = url.toLocalFile(); QRegularExpression rx(".*[.wma$][.mp3$]"); QRegularExpressionMatch rm = rx.match(file_name); if (rm.hasMatch()) { qDebug()<<file_name; } }原文链接:https://www.f2er.com/regex/361834.html