2019-06-13
javascript split string on space or on quotes to array
源自: stackoverflow
问题
var str = 'single words "fixed string of words"';
var astr = str.split(" "); // need fix

i want the array to be like: single, words, fixed string of words.

答案
1
str.match(/\w+|"[^"]+"/g)

//single, words, "fixed string of words"
javascript split string on space or on quotes to array
查看原网页