I have the following program:
var input = "This, is just a test! Every special ? character( including spaces.) should not be caught in the < > array I am about to form!"
var reg = /\W*[\s]/;
var words = input.split(reg);
console.log(words);
My expected output is:
[ 'This', 'is', 'just', ............ 'the', 'array', 'I', 'am', 'about', 'to', 'form' ]
However the output that I get is:
[ 'This', 'is', 'just', ............ 'the', 'array', 'I', 'am', 'about', 'to', 'form!' ]
As you can see it does not split the last word 'form!' properly.It includes '!' with it. Its just the last word it does not split properly. Every other word gets a proper split.
How should I solve this using regular expressions?