title: Is there a way to construct a RegEx to exclude ASCII characters above or below a certain value?
body: <p>We have the need to limit the valid/allowable characters in a string.  The rules we were given are as follows:</p>
  
  <ul>
  <li>Spaces are replaced with underscore</li>
  <li>Length limited to 256 (compiler restriction)</li>
  <li>Must be between ASCII code 32 (space) and 126 (~), and...</li>
  <li>It cannot contain any of the following:
  <ul>
  <li>: (Colon)</li>
  <li>; (Semicolon)</li>
  <li>, (comma)</li>
  <li>' (Single quote)</li>
  <li>" (Double quote)</li>
  <li>\t (Tab)</li>
  <li>\n (New line)</li>
  <li>\r (Carriage return)</li>
  <li>\\ (Backslash)</li>
  </ul></li>
  </ul>
  
  <p>Anything that doesn't meet the rules above should be replaced with an underscore. (The length rule we can simply trim to at the end, unless there is something in RegEx that will address that as well.)</p>
  
  <p>Now I know how to state allowable characters by creating a class like this for say, alphanumeric characters ...</p>
  
  <pre><code>[a-zA-Z0-9]
  </code></pre>
  
  <p>...then using the inverse of that in a Replace call like this (note the leading carat)...</p>
  
  <pre><code>var cleanedString = RegEx.Replace(sourceString, "[^a-zA-Z0-9]", replacementString);
  </code></pre>
  
  <p>...but how can I handle both the range (the "must be between ' ' and '~'" condition) as well as the specifically excluded characters? Do you do it as an 'OR' operation like this?</p>
  
  <pre><code>var cleanedString = RegEx.Replace(sourceString, @"[^ -~]|[;:,'""\t\n\r\\]", replacementString);
  </code></pre>
  
  <p>Note: Is that how you start a range between ' ' (space) and '~'?  Not sure if I have to explicitly escape the space somehow.</p>
  
  <p>More generally, and like the question's title asks, say the rule was it just had to be above 32, but there was no upper limit.  How can you specify such an open-ended range?</p>