title: Ignore certain characters from a character set in regex
body: <p>I have the following code which replaces control characters:</p>
  
  <pre><code>String str = "Apple\n"
                  + "\n"
                  + "\n"
                  + "\n"
                  + "&gt; --"
                  + "\n"
                  + "\n"
                  + "Mango\n"
                  + "\n"
                  + "\n"
                  + "Kiwi\n"
                  + "Papaya\n"
                  + "\n"
                  + "Orange\n";
  
  str = str.replaceAll("(?m)((^[\\p{C}]*)|([\\p{C}]*$))", "");
  </code></pre>
  
  <p>I want to remove all control characters except the new line (\n) from the start of the line and the end of the line. The problem I am having in that <code>\n</code> is a part of <code>\\p{C}</code> set. How do I modify this regex to ensure it replaces all characters except the <code>\n</code> character.</p>