Javascript replace space with regex


Sep 03, 2022
\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






你可能感興趣的文章

CSS Text Shadow Mouse Move Effect

CSS Text Shadow Mouse Move Effect

菜逼八寫Flutter(1) - 環境建置 & 基本介紹

菜逼八寫Flutter(1) - 環境建置 & 基本介紹

C 語言練習程式(5) -- 指標相關程式集錦(4)

C 語言練習程式(5) -- 指標相關程式集錦(4)






留言討論