当前位置:编程学习 > wap >>

一个正则提取问题,求解

这个要提取出一个段HTML中的连接ID和连接名,这里我只写了一个链接作为测试
问题是无论如何也提取不出来。

QString pattern = "<a href=\"http://www.****.com/showpage.asp?id=(.*?)\">(.*?)</a>";
QRegExp rx(pattern);
rx.setCaseSensitivity(Qt::CaseInsensitive);
rx.setMinimal(true);
QString str = "<a href=\"http://www..****.com/showpage.asp?id=17\">红内线直播</a>";
int pos = rx.indexIn(str);
while ((pos = rx.indexIn(str, pos)) != -1) {
QMessageBox::information(this, "匹配了", rx.cap(1));    
pos += rx.matchedLength();//继续寻找下一个匹配
}
--------------------编程问答-------------------- 上面的代码发帖的时候多带了一个点。。

QString pattern = "<a href=\"http://www.****.com/showpage.asp?id=(.*?)\">(.*?)</a>";
QRegExp rx(pattern);
rx.setCaseSensitivity(Qt::CaseInsensitive);
rx.setMinimal(true);
QString str = "<a href=\"http://www.****.com/showpage.asp?id=17\">红内线直播</a>";
int pos = rx.indexIn(str);
while ((pos = rx.indexIn(str, pos)) != -1) {
    QMessageBox::information(this, "匹配了", rx.cap(1));    
    pos += rx.matchedLength();//继续寻找下一个匹配
}
--------------------编程问答-------------------- 我要结帖,来个人接分。。。 --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 正则式有没有问题啊。其中的连续4个*号 --------------------编程问答-------------------- 恩,来接分。。。。。
补充:移动开发 ,  Qt
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,