I have the following sentence:
One Flew Over the Cuckoo's Nest
I'd like to remove any instance of "the" and "'" from the sentence so the output is the following:
Expected output:
one flew over cuckoos nest
I use the following code:
var guess = "One Flew Over the Cuckoo's Nest";
guess = guess.toLowerCase().replace("'", "").replace("the", "");
Actual Output:
one flew over cuckoos nest
The problem is that there's a space appearing after "over" because I'm only removing "the" from that particular sentence and not the space afterwards.
I know I can fix this by using replace("the ", ""); but I would like a better way to achieve the result.
Would there be a regular expression I can use instead?