I have the next input: 8+9
I wold like to extract the numbers and the operators in separate arrays, I have the next code:
const numbers = input.split(/\D/g).filter(Boolean);
console.log("numbersBeforeFilter:", numbers);
const op = input.split(/\d/g).filter(Boolean);
in numbers I have ["8", "9"]
And in operators: ["+"]
Which it's ok, but if I have for example the next expression: -7, I have the next result:
in numbers I have ["7"]
And in operators: ["-"]
Which is wrong because I must have -7 in the numbers array and the operator one empty.
Any ideas?