Including separator characters in String split by string match - Javascript jQuery

Javascript examples for jQuery:String

Description

Including separator characters in String split by string match

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){//from  ww w  . j  a  va2s. com
var sentences = $('#text').val().match(/[^\r\n.|!|?]+(\r\n|\r|\n|[.|!|?])\s*/gi);
console.log(sentences);
    });

      </script> 
 </head> 
 <body> 
  <textarea id="text">First sentence.Second sentence? Third sentence!
Fourth sentence.
</textarea>  
 </body>
</html>

Related Tutorials