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






你可能感興趣的文章

筆記 課程中SQL command 轉SQLite

筆記 課程中SQL command 轉SQLite

[ 紀錄 ] 實戰練習 - 留言版 (實作前端)

[ 紀錄 ] 實戰練習 - 留言版 (實作前端)

CS50 TCP (Transmission Control Protocol)

CS50 TCP (Transmission Control Protocol)






留言討論






2
2
2