The strings are separated into arrays

< H2 > problem description < / H2 > The

string is separated into an array. Due to too many spaces, there is no particularly good idea

< H2 > current implementation method < / H2 >
I think the current implementation method is really a bit troublesome
["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"]
Apr.07,2022

var str = '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';
    const s=str.split(/\s*(?=\|{2}|\&{2})/);
    console.log(s);

want to do this?

const str = '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'

const arr = str.split(/\s+(?:&&|\|\|)\s+/)

console.log(arr)
Menu