title: Removing trailing whitespace and line returns that don't come before/after other characters
body: <p>I have a text area that I'd like to adjust on a form's submit by removing line returns that don't come before or another set of characters (basically removing line removing line breaks that don't serve as paragraph breaks). Here are a few examples of the line breaks I want to remove:</p>
  
  <p><strong>Line Returns - Before &amp; After</strong></p>
  
  <pre><code>/* Space */
  Text
  /* Space */
  </code></pre>
  
  <p><strong>Line Return - Before</strong></p>
  
  <pre><code>/* Space */
  Text
  </code></pre>
  
  <p><strong>Line Return - After</strong></p>
  
  <pre><code>Text
  /* Space */
  </code></pre>
  
  <p>But if there was ever the case where there was in fact text that came after <strong>ONE</strong> line return then it would be considered okay.</p>
  
  <pre><code>Actual Text
  /* Space */
  Actual Text
  </code></pre>
  
  <p>If for argument's sake there was 5 line returns between text, 4 would be removed.</p>
  
  <pre><code>Actual Text
  /* Space */
  /* Space - Remove Me */
  /* Space - Remove Me */
  /* Space - Remove Me */
  /* Space - Remove Me */
  Actual Text
  </code></pre>
  
  <p>While exploring some solutions I thought of using <code>trim()</code> for dealing with trailing whitespace but this would presumably also remove all line returns. What would be the best way to do this?</p>
  
  <p>Here is the context in which I'm replacing the text:</p>
  
  <pre><code>$(function() {
    $(".form").on("submit", function() {
      $("textarea").val().trim();
    });
  });
  </code></pre>