PDA

View Full Version : QRegExp - get only last result



kabanek
3rd November 2010, 21:22
hello

I wrote some code

QRegExp reg("\\s*<h1 class=\"demot\">(\\d+)</h1>\\n");

this should parse a HTML file and find all text in the tag. And the problem is: I cannot get what I want. I wrote:

int pos = 0;

while ((pos = reg.indexIn(result, pos)) != -1) {
qDebug()<<result.mid(pos, pos + reg.matchedLength());
pos += reg.matchedLength();
}
but it doesn't work... What do I do wrong?

Lykurg
3rd November 2010, 21:54
what does "\\s*" and "\\n" in your pattern. Also make yourself familiar with greedy and minimal matching. Then you probably find the problems;)

wysota
3rd November 2010, 22:17
\d+ will give you numbers and not text. And get yourself familiarized with QRegExp::cap(). But in general this is almost bound to fail. Either strip all the tags (which will leave you the text) or use QXmlQuery.