PDA

View Full Version : QRegExp progblem



high_flyer
6th September 2006, 11:51
Hi,

I have the following code, which should find all occorences of '_' which is followed by a number, and replace it with a '.' (dot).
But nothing is being replced...
I guess my QRegExp is wrong, but from reading the docs, I don't understand why...

Thanks.

int main(int argc, char *argv[])
{
//Q_INIT_RESOURCE(application);

QApplication app(argc, argv);
QRegExp re("_(?=\d+)");
QFile ifile("marquard.csv");
QFile ofile("marqurd_new.cvs");
ifile.open(QIODevice::ReadOnly);
ofile.open(QIODevice::WriteOnly);
QTextStream istream(&ifile);
QTextStream ostream(&ofile);
QString text;
istream>>text;
text.replace(re,".");
ostream<<text;
ifile.close();
ofile.close();
return app.exec();
}

danadam
6th September 2006, 13:12
You need two backslashes:

QRegExp re("_(?=\\d+)")

It works for me:

danadam@peasant18]$ cat a.txt
aaaa_3dfd
danadam@peasant18]$ cat b.txt
aaaa.3dfd