PDA

View Full Version : QRegExp for syntax highlight



UVV
23rd August 2011, 07:41
Hi,
I am trying to write a regexp for syntax highlighter to capture only numbers in a text like [12]. So I need to find a number in brackets but I don't need brackets to be captured. Any suggestions?

nix
23rd August 2011, 08:13
This should work :


QString str("test 15[12]dlfk.[dsf[65]");
qDebug() << str;
QRegExp regExp("\\[(\\d+)\\]");
int pos= 0;
while( (pos = regExp.indexIn(str, pos)) != -1)
{
qDebug() << "Found " << regExp.cap(1);
pos += regExp.matchedLength();
}

UVV
23rd August 2011, 20:54
Tnx, I just hoped that that could be done without cap.