簡體   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