如何使用JS正则表达式,在括号之间将所有空格替换为单词SPACE?所以,我想要的是这样的:
myString = "a scentence (another scentence between brackets)"
myReplacedString = myString.replace(/*some regex*/)
//myReplacedString is now "a scentence (anotherSPACEscentenceSPACEbetweenSPACEbrackets)"
编辑: 我尝试过的是这个(我对正则表达式还很陌生)
myReplacedString = myString.replace(/\(\s\)/, "SPACE");
let res = input.replace(/\s+(?=[^)(]*\))/g, "");
,对于较长或内部有大量空格的字符串,我会使用回调函数let res = str.replace(/\([^)(]*\)/g, m => m.replace(/\s+/g, ""));
。 - bobble bubble