728 日 , 2022 17:40:05
正则表达式表示整数、负数和小数
let str = "-10%[-12%,15%]"
// let str = "10%[12%,]"
// let str = "10%[,32%]";
// let str = "[10%,32%]";
// let str = "[,-12%]"
let arr = str.match(/-?([1-9]\d*(\.\d*)*|0\.[1-9]\d*)/g)
let count = 0
arr.forEach(index => {
    if (parseFloat(index) < 0) {
        count += 1;
    }
})
count == 1 ? console.log('橙色') : count > 1 ? console.log('黄色') : console.log('黑色');