title: How to remove control characters from java string?
body: <p>I have a string coming from UI that may contains control characters, and I want to remove all control characters except <strong>carriage returns</strong>, <strong>line feeds</strong>, and <strong>tabs</strong>.</p>
  
  <p>Right now I can find two way to remove all control characters:</p>
  
  <p><strong>1- using guava:</strong></p>
  
  <pre><code>return CharMatcher.JAVA_ISO_CONTROL.removeFrom(string);
  </code></pre>
  
  <p><strong>2- using regex:</strong></p>
  
  <pre><code>return string.replaceAll("\\p{Cntrl}", "");
  </code></pre>