I'm trying to run a script which evaluates only expressions that have add, subs, mults and divs, but can use negative numbers. This negative numbers are taken from instructions like this:
set 1, 5 * D[5]
This implies that you have to store the result of 5 * [whatever it's in a variable]
. If this variable contains a negative number, let's say -2
, the expression will be 5*-2
, and this expression is evaluated by QScriptEngine, resulting 0 (Error). I need to parse expressions like this to be 5*(-2)
. In PERL, a RegExp to do it will be:
$expresion =~ s/\[\\*\\+\\-\\/](\\-\d+)/($1)/g;
How can I do this in Qt?
QString s = "...";
s.replace(QRegExp("[\\*\\+\\-\\/](\\-\\d+)"), "\\1");