连续英文单词去重
程序员文章站
2022-04-26 19:48:37
...
var str = "a mo mo mo fw mo mo" var str2 = ""; do{ str2 = str; str = str.replace(/\s(\w+\s)\1/, " $1"); }while(str.length != str2.length) str = str.replace(/^(\w+\s)\1/, "$1").replace(/(\s\w+)\1$/, "$1"); console.log(str);
下一篇: 正则表达式,分组匹配示例