\smeans any spaces, including newlines and tabs. - space. To remove spaces:
choiceText=choiceText.replace(/ /g,''); // remove spaces
You can remove "any spaces except newlines"; most regex count expressions are \slike[ \t\r\n] , so we just take out \nboth \rand you get:
choiceText=choiceText.replace(/[ \t]/g,''); // remove spaces and tabs