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

Qt Code:
  1. QFile Temp;
  2. QTextStream Output(&Temp);
  3.  
  4. Temp.setFileName("temp.txt");
  5. Temp.open(QIODevice::WriteOnly | QIODevice::Text);
  6.  
  7. // I want to extract "PATIENT0001/", "STUDY0001/", and "SERIES0001 "
  8. QRegExp rx("[a-zA-Z0-9]*[\/\\ ]{1,2}");
  9. QString str = "PATIENT0001/STUDY0001/SERIES0001 DIRECTORY_1";
  10.  
  11. int pos = 0;
  12. while ((pos = rx.indexIn(str, pos)) != -1)
  13. {
  14. Output << rx.cap(1)<<"\n";
  15. pos += rx.matchedLength();
  16. }
To copy to clipboard, switch view to plain text mode