86
rated 0 times
[
87]
[
1]
/ answers: 1 / hits: 20398
/ 11 Years ago, sun, april 28, 2013, 12:00:00
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!
More From » regex