简体   繁体   中英

How to get this regular expression

I have this piece of code:

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

...and I want to get this part:

Memorial do Convento - Texto em Análise

How do I do it? I have tried this:

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

...but the first [^<] doesn't work cause it recognizes only this:

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

You can use captured with this regex :

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

Tried out this regex and it worked

>([^<>]+)<

However parsing HTML with regex isn't the best option

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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