PDA

View Full Version : QRegExp not matching the { character !!



gontham
4th June 2010, 00:42
Hello,

I am trying to match a string within {STRING}.

i tried using the following code:

QRegExp exp("\{.*\}");

and i even tried it for a specific word that i know exists, like:

QRegExp exp("\{file\}");

and i also tried:

QRegExp exp("\\{file\\}");

non of these worked, any ideas on how to do this ?

wysota
4th June 2010, 00:59
Seems to work fine for me...


#include <QtCore>

int main() {
QRegExp rx("\\{.*\\}");
QString str = "bla {xxx} bla";
qDebug() << rx.indexIn(str);
return 0;
}

SixDegrees
4th June 2010, 01:00
I'm not sure what you're trying to accomplish with the curly braces, but Qt RegExps use them as numeric quantifiers; see the documentation at http://doc.qt.nokia.com/4.5/qregexp.html

There are several different systems of regular expressions, each with its own peculiar syntax. The syntax is not interchangeable, and you need to know which you are using, particularly when venturing beyond the most basic expressions.

gontham
4th June 2010, 01:20
thanks wysota, it worked perfect.

i guess the problem was me using this:

str.indexOf(rx);

the index is always -1.