title: javascript split text
body: <p>hi i was wondering if someone could help me i want to split a block of text into sentences then split the sentence into words, i have managed to split the text sentence by sentence but i can not figure out how to split the sentences into words. i know if you replace "input.text.split('\r?\n')" the bracket values with space and it would split the text into word for word but i want it first to split the text sentence by sentence then word by word so that i can add custom styles. code is below , thanks in advance. p.s each sentence has a line break.</p>
  
  <pre><code>    &lt;script type="text/javascript"&gt;
        var parser = {
          outputString:  '',
          subtitle: function(input) {
            var words = input.text.split('\\r?\\n');
            var duration = input.end - input.start;
            var timeStep = duration/words.length;
            for (var i=0, l=words.length; i&lt;l; ++i) {
              var time = Math.round((input.start + i*timeStep) * 1000);
              var text = words[i];
              var safeText = text.replace('"', '\\"');
              parser.outputString += '&lt;span class="arabic" m="'+time+'" oval="'+safeText+'"&gt;'+text+'&lt;/span&gt;';
            } //for
            return parser;
          }, //subtitle
      }; //parser
  
        document.addEventListener('DOMContentLoaded', function(e) {
          var parsed = document.getElementById('parsed');
          parsed.style.width = window.innerWidth - 10 + "px";
          parsed.style.height = window.innerHeight - 10 + "px";
          parsed.value = '&lt;div id="sura-body"&gt;' + parser.outputString + '&lt;/div&gt;';
        }, false);
      &lt;/script&gt;
      &lt;script type="text/javascript" src="paneltext_da.js"&gt;&lt;/script&gt;
        &lt;/head&gt;
       &lt;body&gt;
       &lt;textarea id="parsed"&gt;&lt;/textarea&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>i still can not figure out how to add the html "<code>&lt;p&gt;</code>" to each sentence the data format am using is json. can some one help. thanks</p>
  
  <pre><code>            .subtitle({
            start: 6.057, 
            end: 9.07, 
            text: "Det er et af de vigtigste værktøjer i hverdagen.", 
            target: "subtitlediv"
          })   
          .subtitle({
            start: 9.07, 
            end: 15.02, 
            text: "Det er i browseren vi læser nyheder, ser TV, checker email, snakker med venner, shopper, booker billetter -", 
            target: "subtitlediv"
          })
          .subtitle({
            start: 15.02, 
            end: 18.08, 
            text: "Tusindvis af de ting vi efterhånden gør på nettet.", 
            target: "subtitlediv"
          })
          .subtitle({
            start: 18.081, 
            end: 23.021, 
            text: "Derfor er det også vigtigt hvilken browser vi bruger, og hvordan den virker.", 
            target: "subtitlediv"
          })
  </code></pre>