PDA

View Full Version : QString::replace() with QRegExp capture modification



Lykurg
4th March 2008, 09:14
Hi,

I want to capitalize all letters in an <b> tag (and remove the tag):


QRegExp rx("\\<b\\>(.*)\\</b\\>");
rx.setMinimal(true);
str.replace(rx, QString("\\1").toUpper());

but '\\1' is unfortunately replaced after the toUpper():(
So, how can I achieve to upper case the letters in a tag?



Thanks,

Lykurg

wysota
4th March 2008, 10:50
QRegExp rx("....");
rx.setMinimal(true);
int s = -1;
while((s = rx.indexIn(str, s+1))>=0){
str.replace(s, rx.cap(0).length(), rx.cap(1).toUpper());
s+= rx.cap(1).length();
}