Hi,

I need to split string such as "Stage1 <= 4.4e-05 || Stage == 1.2 && Comp >= 1.4e+03 || A+e-C > D" to get all variables in the expression.

In the example string, the result should be "Stage1", "4.4e-05", "Stage", "1.2", "Comp", "1.4e+03", "A", "e", "C", "D"

I am using QRegExp rx( "[+\\-*/(),<>&=| ]" ) to split it.

However, it also split "4.4e-05" and "1.4e+03". How can I write the QRegExp to split it without breaking scientific notation.

Thanks!


Here is sample code

Qt Code:
  1. #include <QStringList>
  2. #include <QRegExp>
  3. #include <QDebug>
  4.  
  5. int main()
  6. {
  7. QString str( "Stage1 <= 4.4e-05 || Stage == 1.2 && Comp >= 1.4e+03 || A+e-C > D" );
  8. qDebug() << "str =" << str;
  9.  
  10. QRegExp rx( "[+\\-*/(),<>&=| ]" );
  11. QStringList strList = str.split( rx, QString::SkipEmptyParts );
  12.  
  13. qDebug() << "strList =" << strList;
  14. }
To copy to clipboard, switch view to plain text mode