Javascript replace space with regex


\s : means "one space"

\s+ : means "one or more spaces"

let stringWithSpace = '  A B  C   D EF ';

console.log(str.replace(/\s/g, '#'));                                
// ##A#B##C###D#EF# => means one space replace by one #;

console.log(str.replace(/\s+/g, '#'));                             
// #A#B#C#D#EF#  => means one or more spaces, all replace by #;
#javascript #replace #RegEx






你可能感興趣的文章

Filecoin Spec 中文 -- 2

Filecoin Spec 中文 -- 2

匯入小工具 (3) - 設定環境變數,才不會被看光光

匯入小工具 (3) - 設定環境變數,才不會被看光光

【Day06】threading用多執行緒更快完成影片下載

【Day06】threading用多執行緒更快完成影片下載






留言討論