Split a string at special character via split method and regex - Javascript String Operation

Javascript examples for String Operation:String Split

Description

Split a string at special character via split method and regex

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(){/*www.j a va  2 s  .c  om*/
var letters = "jon-doe@email.com";
var email = letters.substr(0, letters.indexOf('@'));
var parts = email.split(/[^A-Za-z]/);
console.log(parts);
    }

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

Related Tutorials