Use positive lookahead:
"asdf a b c2 ".split(/(?= )/)
// => ["asdf", " a", " ", " b", " c2", " "]
Post-edit EDIT: As I said in comments, the lack of lookbehind makes this a bit trickier. If all the words only consist of letters, you can fake lookbehind using \b
word boundary matcher:
"asdf a b c2 ".split(/(?= )|\b/)
// => ["asdf", " ", "a", " ", " ", "b", " ", "c2", " "]
but as soon as you get some punctuation in, it breaks down, since it does not only break on spaces:
"asdf-eif.b".split(/(?= )|\b/)
// => ["asdf", "-", "eif", ".", "b"]
If you do have non-letters you don't want to break on, then I will also suggest a postprocessing method.
Post-think EDIT: This is based on JamesA's original idea, but refined to not use jQuery, and to correctly split:
function chop(str) {
var result = [];
var pastFirst = false;
str.split(' ').forEach(function(x) {
if (pastFirst) result.push(' ');
if (x.length) result.push(x);
pastFirst = true;
});
return result;
}
chop("asdf a b c2 ")
// => ["asdf", " ", "a", " ", " ", "b", " ", "c2", " "]