I am trying to split a string into an array of words, however I want to keep spaces after each word. Here is what I am trying:
var re = /[a-z]+[$\s+]/gi;
var test = "test one two three four ";
var results = test.match(re);
Expected results:
[0]: "test "
[1]: "one "
[2]: "two "
[3]: "three "
[4]: "four "
However, it matches only one space after each word:
[0]: "test "
[1]: "one "
[2]: "two "
[3]: "three "
[4]: "four "
What am I doing wrong?
source
share