I am trying to split a string into an array of single words in Javascript. First step was quite easy:
words = text.split(/\b\s+(?!$)/);
This solution works fine, except it doesn't use punctuation characters as separators. For example writing "Hello! How are you?", in the array of words I find "Hello!", "How", "are", "you?".
I solved this problem with a not very elegant solution (but it works!):
str= str.replace(",","");
str= str.replace(".","");
str= str.replace("!","");
str= str.replace("?","");
But there is still a big problem. If str contains any not english character (such as italian characters ò,à,è,ù), method split doesn't split the words.
For example if text is "Perché sei partito?", "Perché sei" is splitted into a single element of array words (as if it were a single word).
Any solution? Thanks a lot for helping!