-3

I have a string "str1+str2-str3*str4".

I want to split it so I get an array

['str1','+','str2','-','str3','*','str4'].

Could someone help provide a solution?

ggorlen
  • 33,459
  • 6
  • 59
  • 67
Nikhil
  • 27
  • 4

1 Answers1

1

If JS split lets capture groups become elements, then this should work

/([-+*\/])/

if not, I suggest using a regular find all type thing
using this

/([-+*\/]|[^-+*\/]+)/

otherwise, I'll just delete this.