Sorry if this has been asked before, but I'm trying to get an array of words from a string like this:
"Exclamation! Question? \"Quotes.\" 'Apostrophe'. Wasn't. 'Couldn't'. \"Didn't\"."
The array is supposed to look like this:
[
"exclamation",
"question",
"quotes",
"apostrophe",
"wasn't"
"couldn't",
"didn't"
]
Currently I'm using this expression:
sentence.toLowerCase().replace(/[^\w\s]/gi, "").split(" ");
The problem is, it removes apostrophes from words like "wasn't", turning it into "wasnt".
I can't figure out how to keep the apostrophes in words such as that.
Any help would be greatly appreciated!
var sentence = "Exclamation! Question? \"Quotes.\" 'Apostrophe'. Wasn't. 'Couldn't'. \"Didn't\".";
console.log(sentence.toLowerCase().replace(/[^\w\s]/gi, "").split(" "));