title: RegEx to remove all control / invisible characters EXCEPT CR or LF
body: <p>I am trying to use regex (.Net) to "sanitize" a Unicode input string -- the requirement is to remove all invisible characters / control characters EXCEPT CR (carriage returns) and LF (linefeeds).  In other words, keep all valid printable characters (English and French) including CR and LF.</p>
  
  <p>I have tried the following (just using the underscore to see what was replaced), but it also removes CR / LF ...</p>
  
  <pre><code>clean_str = Regex.Replace( in_str, "\p{C}+", "_" )
  </code></pre>
  
  <p>Also tried:</p>
  
  <pre><code>clean_str = Regex.Replace( in_str, "(\p{Cf}|\p{Co}|\p{Cs}|\p{Cn}|[\x00-\x09]|\x0b|\x0c|[\x0e-\x1f]|\x7f)+", "_" )
  </code></pre>
  
  <p>From <a href="http://www.regular-expressions.info/unicode.html" rel="nofollow">http://www.regular-expressions.info/unicode.html</a> ...</p>
  
  <pre><code>p{C} or \p{Other}: invisible control characters and unused code points.
  
   ◦\p{Cc} or \p{Control}: an ASCII 0x00–0x1F or Latin-1 0x80–0x9F control character.
   ◦\p{Cf} or \p{Format}: invisible formatting indicator.
   ◦\p{Co} or \p{Private_Use}: any code point reserved for private use.
   ◦\p{Cs} or \p{Surrogate}: one half of a surrogate pair in UTF-16 encoding.
   ◦\p{Cn} or \p{Unassigned}: any code point to which no character has been assigned.
  </code></pre>
  
  <p>Guru's - if you have a better / more efficient way -- please post !</p>
  
  <p>Thanks in advance!</p>