如果我有一个在单词之间有多个空格的字符串:
Be an excellent person
使用 JavaScript/正则表达式,如何删除多余的内部空格,使其变为:
Be an excellent person
最佳答案
您可以使用正则表达式 /\s{2,}/g
:
var s = "Be an excellent person"
s.replace(/\s{2,}/g, ' ');
关于javascript - 在 JavaScript/regex 中,如何删除字符串中的双空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4467024/