QRegExp - get only last result
hello
I wrote some code
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:
Code:
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?
Re: QRegExp - get only last result
what does "\\s*" and "\\n" in your pattern. Also make yourself familiar with greedy and minimal matching. Then you probably find the problems;)
Re: QRegExp - get only last result
\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.