PDA

View Full Version : help on qregexp



sanqt
20th February 2011, 17:11
hello~

I have a string like following,

"%aaa\nbbb"

and I want to replace "%aaa" to "x".

Here is my code.

QString text = "%aaa\nbbb";
QRegExp rx = "\\b%aaa";
text.replace( rx, "x" );
qDebug( "%s", qPrintable( text ) );

Output:
%aaa\nbbb

Unfortunately, "%aaa" never changed.
If I remove "%" character then that is done as I wants it done.

I don't know how can I replace strings start with "%" or "$".

SixDegrees
20th February 2011, 17:39
I don't have the documentation in front of me, but I'd guess you have to escape special characters. If you want to match a literal '%', you likely have to use '\%'.