johnny_sparx
23rd February 2006, 23:19
I wish to extract some parts of a formatted string, so I opted to use QRegExp. I tested the expression so I know it works alright, but can't seem to get it to work using Qt:confused: .
A snippet of test code is below - it is supposed to dump the sub-expressions into a text file.
Any help is appreciated.
JS
QFile Temp;
QTextStream Output(&Temp);
Temp.setFileName("temp.txt");
Temp.open(QIODevice::WriteOnly | QIODevice::Text);
// I want to extract "PATIENT0001/", "STUDY0001/", and "SERIES0001 "
QRegExp rx("[a-zA-Z0-9]*[\/\\ ]{1,2}");
QString str = "PATIENT0001/STUDY0001/SERIES0001 DIRECTORY_1";
int pos = 0;
while ((pos = rx.indexIn(str, pos)) != -1)
{
Output << rx.cap(1)<<"\n";
pos += rx.matchedLength();
}
A snippet of test code is below - it is supposed to dump the sub-expressions into a text file.
Any help is appreciated.
JS
QFile Temp;
QTextStream Output(&Temp);
Temp.setFileName("temp.txt");
Temp.open(QIODevice::WriteOnly | QIODevice::Text);
// I want to extract "PATIENT0001/", "STUDY0001/", and "SERIES0001 "
QRegExp rx("[a-zA-Z0-9]*[\/\\ ]{1,2}");
QString str = "PATIENT0001/STUDY0001/SERIES0001 DIRECTORY_1";
int pos = 0;
while ((pos = rx.indexIn(str, pos)) != -1)
{
Output << rx.cap(1)<<"\n";
pos += rx.matchedLength();
}