I have a string:
this.sentence = 'I have a brother, sister, a dog, and a cat.'
I want to convert it into an array so that each word and each punctuation mark is a separate value. Using .split(" ")
gives me an array of words, but does not put each comma and a dot as a separate value.
How can I do this so that I get such array
["I", "have", "a", "brother", ",", "sister", ",", "a", "dog", ",", "and", "a", "cat", "."]
I don’t really want to use .match
and regex as I need to include special Polish characters in my sentences
2
Answers
Simple way to split them with regex
But, not sure if you don’t want use regex.