I have string like as "1 + 2 - 3 + 10
".
I want split it to "1", "+2", "-3", "+10"
.
Here is my code.
var expression = "1 + 2 - 3 + 10";
expression = expression.replace(/s+/g, '');
let fields = expression.split(/([+-]d+)/g);
console.log(fields);
But result is
["1", "+2", "", "-3", "", "+10", ""]
How can I make result ["1", "+2", "-3", "+10"]
?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…