I have a string where I need to separate it by +-*/ and put it into array.
I've tried this code that I also found here, but it doesn't seem to be working. It gives me the error "Invalid regular expression: /+|-|*|//: Nothing to repeat."
var separators = ['+', '-', '*', '/'];
var numbers = x.split(new RegExp(separators.join('|'), ''));
Any advice on how should I do this?
Try this.
var str = "i-have_six*apples+doyou/know.doe";
console.log(str.split(/[.\*+-/_]/));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With