Javascript replace space with regex


Jan 08, 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






你可能感興趣的文章

Hexo 想 deploy 在 GitHub 以外的地方

Hexo 想 deploy 在 GitHub 以外的地方

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

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

Command line:command line interface 介紹及基本指令

Command line:command line interface 介紹及基本指令






留言討論






2
2
2