Javascript examples for RegExp:Match Space
Create your own trim() with replace() and regex to remove empty space from string
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/*from www. j a v a2 s . c o m*/ function myTrim(x) { return x.replace(/^\s+|\s+$/gm,''); } function myFunction() { var str = myTrim(" Hello World! "); console.log(str); } myFunction(); } </script> </head> <body> </body> </html>