繁体   English   中英

如何获得这个正则表达式

[英]How to get this regular expression

我有这段代码:

<a href="http://www.fnac.pt/Memorial-do-Convento-Texto-em-Analise-Varios/a242166" class="fontbigger">Memorial do Convento - Texto em Análise</a>

...我想得到这一部分:

Memorial do Convento - Texto em Análise

我该怎么做? 我已经试过了:

<a href="[^<]+" class=".+">(.+)</a>

...但是第一个[^<]不起作用,因为它只能识别以下内容:

http://www.fnac.pt/Memorial-do-Convento-Texto-em-Analise-Varios/

您可以使用此正则表达式 捕获

QRegularExpression regex("<a.*?>(.*?)<\\/\\s*a\\s*>", QRegularExpression::MultilineOption);
QRegularExpressionMatch match = regex.match(resultHTML);
QString output = match.captured(1);

尝试了这个正则表达式并有效

>([^ <>] +)<

但是,使用正则表达式解析HTML并不是最佳选择

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM