Qt正则表达式匹配HTML标签InnerText [英] Qt Regex matches HTML Tag InnerText

查看:511
本文介绍了Qt正则表达式匹配HTML标签InnerText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含< pre> ...< / pre> 标记的html文件。什么正则表达式是必要的预的之内的所有内容相匹配



  QString的图案=LT;预>(*)< /预>中; 
QRegExp rx(pattern);
rx.setCaseSensitivity(cs);

int pos = 0;
QStringList列表; ((pos = rx.indexIn(clipBoardData,pos))!= -1){
list<< rx.cap(1);
pos + = rx.matchedLength();

$ / code $ / pre
$ b $ list.count()总是0 /

解决方案

HTML不是正则语言,你不用正则表达式来解析它。



相反,使用 QXmlSimpleReader 加载XML,然后 QXmlQuery 找到PRE节点,然后提取其内容。


I have a html file with one <pre>...</pre> tag. What regex is necessary to match all content within the pre's?

QString pattern = "<pre>(.*)</pre>";
QRegExp rx(pattern);
rx.setCaseSensitivity(cs);

int pos = 0;
QStringList list;
while ((pos = rx.indexIn(clipBoardData, pos)) != -1) {
  list << rx.cap(1);
  pos += rx.matchedLength();
}

list.count() is always 0

解决方案

HTML is not a regular language, you do not use regular expressions to parse it.

Instead, use QXmlSimpleReader to load the XML, then QXmlQuery to find the PRE node and then extract its contents.

这篇关于Qt正则表达式匹配HTML标签InnerText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆