如何在 JavaScript 中使用正則表示式來移除空格?
要移除 JavaScript 中的空格,你可以嘗試執行以下正則表示式。它將從一個字串中移除空格 −
示例
<html> <head> <script> var str = "Welcome to Tutorialspoint"; document.write(str); //Removing Spaces document.write("<br>"+str.replace(/\s/g, '')); </script> </head> <body> </body> </html>
輸出
廣告