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
#include <QStringList>
#include <QRegExp>
#include <QDebug>
int main()
{
QString str
( "Stage1 <= 4.4e-05 || Stage == 1.2 && Comp >= 1.4e+03 || A+e-C > D" );
qDebug() << "str =" << str;
qDebug() << "strList =" << strList;
}
#include <QStringList>
#include <QRegExp>
#include <QDebug>
int main()
{
QString str( "Stage1 <= 4.4e-05 || Stage == 1.2 && Comp >= 1.4e+03 || A+e-C > D" );
qDebug() << "str =" << str;
QRegExp rx( "[+\\-*/(),<>&=| ]" );
QStringList strList = str.split( rx, QString::SkipEmptyParts );
qDebug() << "strList =" << strList;
}
To copy to clipboard, switch view to plain text mode
Bookmarks