PDA

View Full Version : QRegExp help



Lele
8th February 2008, 09:51
Hi all,
maybe this is not only a Qt question.
I'm using QRegExp for replace any occourrence of a word composed by one or two letters.
I don't get what expected, what I'm doing wrong?
thanks for any help/



QString resS = QString("a la test da che da me asdf non va");
resS.replace(QRegExp("[a-z]{1,2}"), "X");


I get this:
X X XX X XX X X XX XX X

instead of
X X test X che X X asdf non X

jpn
8th February 2008, 09:57
Try adding word boundaries:


QRegExp("\\b[a-z]{1,2}\\b")

Lele
8th February 2008, 10:07
Thanks a lot, it works!