I need help splitting a string in javascript by space (" "), ignoring space inside quotes expression.
I have this string:
var str = 'Time:"Last 7 Days" Time:"Last 30 Days"';
I would expect my string to be split to 2:
['Time:"Last 7 Days"', 'Time:"Last 30 Days"']
but my code splits to 4:
['Time:', '"Last 7 Days"', 'Time:', '"Last 30 Days"']
this is my code:
str.match(/(".*?"|[^"s]+)(?=s*|s*$)/g);
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…