const str = "This this sentence has has double words."; str.replace(/\b(\w+)\s+\1\b/gi, '$1'); // => "This sentence has double words."