问题描述字符串分隔成数组,由于空格处过多,没有特别好的思路当前实现方法我觉得现在的实现方法实在有点麻烦varstr='sourceIp==86.248.198.93&&sourceIp!=86.248.198.93||sourceIp==86.248.198.93||sourceIp!=86.248.198.93&&sourceIp==86.248.198.93:737&&sourceIp!=86.248.198.93:737||sourceIp==86.248.198.93:737||sourceIp!=86.248.198.93:737'vararr=str.split('')varnewArr=['']arr.forEach(item=>{letoldValue=newArr[newArr.length-1].trim()if(item==='&&'||item==='||'){newArr.push(item)}else{newArr[newArr.length-1]=oldValue+''+item}})相关代码'sourceIp==86.248.198.93&&sourceIp!=86.248.198.93||sourceIp==86.248.198.93||sourceIp!=86.248.198.93&&sourceIp==86.248.198.93:737&&sourceIp!=86.248.198.93:737||sourceIp==86.248.198.93:737||sourceIp!=86.248.198.93:737'你期待的结果是什么?实际看到的错误信息又是什么?["sourceIp==86.248.198.93","&&sourceIp!=86.248.198.93","||sourceIp==86.248.198.93","||sourceIp!=86.248.198.93","&&sourceIp==86.248.198.93:737","&&sourceIp!=86.248.198.93:737","||sourceIp==86.248.198.93:737","||sourceIp!=86.248.198.93:737"]
2 回答
陪伴而非守候
TA贡献1757条经验 获得超8个赞
varstr='sourceIp==86.248.198.93&&sourceIp!=86.248.198.93||sourceIp==86.248.198.93||sourceIp!=86.248.198.93&&sourceIp==86.248.198.93:737&&sourceIp!=86.248.198.93:737||sourceIp==86.248.198.93:737||sourceIp!=86.248.198.93:737';consts=str.split(/\s*(?=\|{2}|\&{2})/);console.log(s);
慕田峪9158850
TA贡献1794条经验 获得超7个赞
要这样?conststr='sourceIp==86.248.198.93&&sourceIp!=86.248.198.93||sourceIp==86.248.198.93||sourceIp!=86.248.198.93&&sourceIp==86.248.198.93:737&&sourceIp!=86.248.198.93:737||sourceIp==86.248.198.93:737||sourceIp!=86.248.198.93:737'constarr=str.split(/\s+(?:&&|\|\|)\s+/)console.log(arr)
添加回答
举报
0/150
提交
取消