I wanted my myResult = [ ’40’, ‘-‘, ‘(‘, ’60’, ‘*’, ‘2’, ‘)’ ]
let myInput = '40-(60*2)';
let myResult = myInput.split(/([*\/+-])/);
console.log(myResult)
>Solution :
Include parentheses in the character set, then use .match instead of .split and alternate with numeric characters.
let myInput = '40-(60*2)';
let myResult = myInput.match(/[()*\/+-]|\d+/g);
console.log(myResult)