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






你可能感興趣的文章

CH4 字元與字串筆記

CH4 字元與字串筆記

滲透測試基本技術 第三章 (005)

滲透測試基本技術 第三章 (005)

簡單入門 Grid 屬性/用法/使用情境

簡單入門 Grid 屬性/用法/使用情境






留言討論