I want to get a True or False value by putting a value in the sTest_Val_1 ("30") variable.
So we try to split and separate variables and operators.
At first I used the following source code.
However, this source code has caused problems because it is also splitting "_" from sTest_Val_1.
I could not split properly because of special characters in variables. So I could not put a value of "30" into the variable.
var expression = "sTest_Val_1 < 50"; //or "sTest_Val_1<50"
var copy = expression; //"sTest_Val_1 < 50"
expression = expression.replace(/[0-9a-zA-Z]+/g, "#"); //"#_#_# < #"
var numbers = copy.split(/[^0-9a-zA-Z\.]+/); //[sTest,Val,1,50]
var operators = expression.split("#").filter(function (n) { return n }); //[_,_, < ]
var result = [];
var sRst = "";
result.push(numbers[i]);
sRst += numbers[i];
if (i < operators.length) {
result.push(operators[i]);
sRst += operators[i];
console.log(sRst);
return eval(sRst); // I want True, False
The value of sTest_Val_1 is defined in another page. (i get this value to javascript object when first page loaded.)
string sTest_Val_1 = "30";
string sTest_Val_2 = "30";
string sTimeVal_1 = "65380";
// ....
"sTest_Val_1" This value can only contain alphabetic characters in the first character.
However, the length of the characters is random, and the special characters in the characters are also random. (<,>, +, -, and = are not included.)
My English is not good enough. Please understand.