我编写正则表达式以获取html中的所有ref链接。
QRegExp bodylinksrx("(<a\\s+href\\s*=\\s*[^<>]*\\s*>[^<>]*</a>)");
QStringList bodylinks;
pos = 0;
while ((pos = bodylinksrx.indexIn(htmlcode, pos)) != -1)
{
bodylinks << bodylinksrx.cap(1);
pos += bodylinksrx.matchedLength();
}我收到的结果是:
("<a href="http://somehref" class="someclass">href text...</a>", "<a href="http://somehref" class="someclass">href text...</a>", ......")但是我需要只包含"http://somehref" "href text..." "http://somehref" "href text..." ....的接收列表
发布于 2014-05-08 16:40:47
首先,有您的读这个?,其次,如果您确定您知道您正在做什么,并且肯定知道您想要这样做,尝试使用查找和查找您的锚标记断言。
((?<=<a\\s+href\\s*=\\s*[^<>]*\\s*>)[^<>]*(?=</a>))编辑:不幸的是,这将不起作用(至少对qt4.8)作为查找断言不支持。您只需迭代创建的列表,并将所需的位匹配如下:
[^<>]*(?=<)然后使用它,或者使用捕获文本函数提取您想要的部分,并将其括起来如下所示:
<a\\s+href\\s*=\\s*[^<>]*\\s*>([^<>]*)</a>https://stackoverflow.com/questions/23547512
复制相似问题