Splitting a string and preserving the spaces - Javascript String

Javascript examples for String:split

Description

Splitting a string and preserving the spaces

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 . jav a2 s . co m


var str   = "please     help me ";
var split = str.split(/(\S+\s+)/).filter(function(n) {return n});
console.log(split)


    }

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

Related Tutorials