title: Replace Space with Newline in JavaScript?
body: <p>I need to create a new line after each <code>&lt;li&gt;</code> element.  I stripped the <code>&lt;li&gt;</code> of spaces using <code>/\s*&lt;li&gt;/g</code>, but it's not working like I want it to work.</p>
  
  <p>Here is the <a href="http://jsfiddle.net/3jthN/19/" rel="nofollow">jsFiddle</a>.</p>
  
  <p>For example:</p>
  
  <p>Processing this text using <code>doIt(){...}</code></p>
  
  <pre><code>&lt;ol&gt;
   &lt;li&gt;Hello world! :)&lt;/li&gt; 
    &lt;li&gt;Hello how are you&lt;/li&gt; 
     &lt;li&gt;good&lt;/li&gt;
  &lt;/ol&gt;
  </code></pre>
  
  <p>I used <code>/\s*&lt;li&gt;/g</code> to remove <strong>any amount of</strong> space before <code>&lt;li&gt;</code>, and it gives you:</p>
  
  <pre><code>1. Hello world! :)2. Hello how are you3. good
  </code></pre>
  
  <p>Is there a way to make the above, look like:</p>
  
  <pre><code>1. Hello world! :)
  2. Hello how are you
  3. good
  </code></pre>
  
  <p>Here is <code>doIt(){...}</code></p>
  
  <pre><code>function doIt() {
  var input = document.getElementById('input');
  var olPatt = /&lt;ol&gt;\s*((?:&lt;li&gt;.+&lt;\/li&gt;\s*)+)&lt;\/ol&gt;/g;
  var i = 1;
  
  input.value = input.value.replace(olPatt, function (n, listItems) {
      return listItems.replace(/\s*&lt;li&gt;/g, function() {return i++ + '.' + ' ';}).replace(/&lt;\/li&gt;/g, '');
  });
  
  input.value = input.value.replace(ulPatt, function (n, listItems) {
      return listItems.replace(/\s*&lt;li&gt;/g, function () {
      return i++ + '.' + ' ';
      }).replace(/&lt;\/li&gt;/g, '');
  });
  }
  </code></pre>