Hello my problem begins when i try to split with regexp to get multilevel from a math expresion.
Like i have this expresion :
((V1 == V1 && (V1 == V1 && (V1 == V1 && (V1 == V1 && V1 == V1 && V1 == V1) && V1 == V1)) && V1 == V1) && (V1 == V1))
And i need to split like multi level from one pregenerated code like this where i can only split by the () because everything else its pregenerated are components (V1) and operations (&&, ||, =<, =>) and the operaations and components i cant use them to split cuz could be anything value (in the operation are like 10 operations but the values of components could be anything they are generated) expecting something like this in the frist level:
ONE: (V1 == V1 && (V1 == V1 && (V1 == V1 && (V1 == V1 && V1 == V1 && V1 == V1) && V1 == V1)) && V1 == V1) && (V1 == V1)
and in the second level i would like to take the frist main operation and the second like:
THW: (V1 == V1 && (V1 == V1 && (V1 == V1 && (V1 == V1 && V1 == V1 && V1 == V1) && V1 == V1)) && V1 == V1)
THW: (V1 == V1)
And so with every possible deep level like in level 3:
THREE: (V1 == V1 && V1 == V1)
This frist THREE LEVEL should be dragged from here in the full viewed:
((V1 == V1 "<-- this its the frist" && (V1 == V1 && (V1 == V1 && (V1 == V1 && V1 == V1 && V1 == V1) && V1 == V1)) && V1 == V1 "<-- this its the second one") && (V1 == V1))
THREE: (V1 == V1)
And this second from THREE LEVEL should be dragged from here in the full viewed:
((V1 == V1 && (V1 == V1 && (V1 == V1 && (V1 == V1 && V1 == V1 && V1 == V1) && V1 == V1)) && V1 == V1) && (V1 == V1 "<-- and this one"))
And it goes and goes no matter how many levels there are the problem... how i split every single one only having "(" and ")"
this is a sample code that i have test("this is not generated its just a example that i have generated and copyed just to test the split thing but it should work with any generated expresion"):
var expressionToGenerateCode = '((V1 == V1 && (V1 == V1 && (V1 == V1 && (V1 == V1 && V1 == V1 && V1 == V1) && V1 == V1)) && V1 == V1) && (V1 == V1))';
/*var regExp = /[(](.*)[)]+/i;
var regExpLevel2 = /[(.*)]+/i;
var matches = expressionToGenerateCode.split(regExp);
for(var i = 0; i < matches.length; i++){
if (matches[i] != '') {
var str = matches[i];
console.log('ONE: '+ str);
var matches_thw = str.split(regExpLevel2);
for(var e = 0; e < matches_thw.length; e++){
var str2 = matches_thw[e];
console.log('THW: '+ str2);
}
}
}
Output log:
ONE: (V1 == V1 && (V1 == V1 && (V1 == V1 && (V1 == V1 && V1 == V1 && V1 == V1) && V1 == V1)) && V1 == V1) && (V1 == V1) ex-generator.aitssc.com:80:14
THW: ex-generator.aitssc.com:84:19
THW: V1 == V1 &&
ex-generator.aitssc.com:84:19
THW: V1 == V1 && V1 == V1 && V1 == V1 ex-generator.aitssc.com:84:19
THW: && V1 == V1
ex-generator.aitssc.com:84:19
THW: && ex-generator.aitssc.com:84:19
THW: V1 == V1 ex-generator.aitssc.com:84:19
THW:
Its not a easy resolve problem i hope some genius can give a hand or any idea or logic... i dont necesarry made it like in the example code and output its just a example how i should start it but if someone have a better idea please give your solution, thanks and have a nice day guys.
Aucun commentaire:
Enregistrer un commentaire