我有一个字符串,可以说'C1 AND C2 OR C3 (~!@#$%) AND C4 OR C5'......现在我实际上已经将它拆分并保存在一个数组(inArray)中,即
function removeCondition(condition,input){
//Condition is the String ie(C1 And C2) and input is the suffix no ie (3 for C3)
condition = condition.replace(new RegExp("\n","g")," ");
var inArray = condition.split(' ');
var conditionRemoved = false;
inArray.forEach(function(v,i,a){
if(v.indexOf("C"+input) > -1){
if(i+2 < a.length){
//some function i want
//inArray.splice(i,2);
}
else{
inArray.splice(i-1,2);
}
inArray.join(' ');
}
}
}//editor: added this bracket to balance the closing brackets
当我想要所需的条件时,上述if()
条件得到满足,即在这种情况下C3
..现在我想删除C3
下一个运算符(可以是 OR/AND)以及介于两者之间的所有垃圾......所以对于上面的例子我的输出必须是C1 AND C2 OR C4 OR C5
.