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 .
A snippet of test code is below - it is supposed to dump the sub-expressions into a text file.
Any help is appreciated.
JS
Temp.setFileName("temp.txt");
// 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();
}
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();
}
To copy to clipboard, switch view to plain text mode
Bookmarks