标签:
1 //将逗号和"|" 替换为"and" 和 "or" 2 3 var text=‘A,B,C|D,E,F|G|K‘; 4 (function parseSigningRule(text){ 5 if(isEmpty(text)) 6 return text; 7 var output = ‘‘; 8 var array = text.split(","); 9 var signatureCount = array.length; 10 $.each(array, function(idx, val){ 11 var wrapNeeded = false; 12 if(val.split("|").length > 1 ){ 13 wrapNeeded = true; 14 } 15 16 if(signatureCount == 1){ 17 wrapNeeded = false; 18 } 19 20 val = val.replace(/\|/g , " or "); 21 22 if(wrapNeeded){ 23 val = ‘( ‘+val+‘ )‘; 24 } 25 if(idx > 0){ 26 output += ‘ and ‘; 27 } 28 output += val; 29 }); 30 31 console.log(output); 32 return output; 33 })(text); 34 35
标签:
原文地址:http://www.cnblogs.com/angleBlue/p/4424754.html