In Javascript :
var myString = \"This is my string\";
console.log(myString.split(/(\\s)/));
Output : [\"This\", \" \", \"is\", \" \"
The two regexs you're using are only slightly different.
/(\s)/ has a capture group of \s, so when used with split() it will add the anything found in the capture group to the array.
The regex /\s/ has no capture group, so split() ignores the matches and does not add them to the array.
Similarly, if you execute:
var myString = "This is my string";
console.log(myString.split(/(my)/)); //includes matched capture group in results
console.log(myString.split(/my/)); //ignores matches
Will output:
["This is ", "my", " string"]
["This is ", " string"]
Hope that helps!