I want to recover a QString between brakets.
For example i have "Cos([Temperature1]*25)+58" and i want recover just "[Temperature1]*25" ,
can i do it with a QRegExp or is there a best way?
Thanks!
I want to recover a QString between brakets.
For example i have "Cos([Temperature1]*25)+58" and i want recover just "[Temperature1]*25" ,
can i do it with a QRegExp or is there a best way?
Thanks!
Yes, you can do it with a regular expression.
The following regexp should match your case:
Qt Code:
To copy to clipboard, switch view to plain text mode
i tried it but it doesn't work
i tried this :
Qt Code:
QStringList listMul; listMul = formule.split(regExp);To copy to clipboard, switch view to plain text mode
and i find in the list Cos, [Temperature1] , 25 and +58 but when i changed * by + i find Cos, [Temperature1]+25 and +58.
I want the same thing with * : Cos, [Temperature1]*25 and +58.
Last edited by hassinoss; 26th February 2014 at 17:37.
You can also use indexOf() to search for the opening parenthese, then indexOf with that start index to search for the closing parentheses and then use QString::mid() to get the part that is of interest to you.
Cheers,
_
Wysota's suggestion is not quite right but it really doesn't matter because what you asked for was not what you wanted anyway.
You actually wanted to split the expression into tokens. This a non-trivial exercise in general cases, but for your specific case this works:
Qt Code:
// The incredibly simple qDebug() << list; // or the more involved but more flexible list.clear(); int pos = 0; while ((pos = re.indexIn(formule, pos)) != -1) { list << re.cap(0); pos += re.matchedLength(); }; qDebug() << list;To copy to clipboard, switch view to plain text mode
Thanx for your replies , they were very useful
Bookmarks