Remove all whitespaces except when space is part of an exact string - Javascript String

Javascript examples for String:replace

Description

Remove all whitespaces except when space is part of an exact string

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from  ww  w  . ja v a2  s . co m*/
var string = "<h1 class='' id='' title=''></h1>";
var regexp = /(\w+='')\ /g;
var string = string.replace(regexp, "$1");
console.log(string);
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials