「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()
条件は、目的の条件が必要な場合に満たされます。つまり、この場合..次の演算子(OR / ANDである可能性があります)とその間にあるすべてのジャンクをC3
削除したい..上記の例の場合C3
私の出力はでなければなりませんC1 AND C2 OR C4 OR C5
。