I want to split a string into an array using “space and the comma” (” ,”) as the separator. Through looking through some similar questions I figured out how to make them work as one separator. However I want them to work ONLY as one. So I do not want the array to be separated by only comma’s or only spaces.
So I’d like the string "txt1, txt2,txt3 txt4, t x t 5" become the array txt1, "txt2,txt3 txt4", "t x t 5"
Here is my current code which doesn’t do this:
var array = string.split(/(?:,| )+/)
Here is a link to the jsFiddle: http://jsfiddle.net/MSQxk/
Just do:
var array = string.split(", ");