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!
Printable View
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:
i tried it but it doesn't work :(
i tried this :
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.
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:
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;
Thanx for your replies , they were very useful