title: How to filter out characters that aren't letters, numbers or punctuation
body: <p>I have a string that will have a lot of formatting things like bullet points or arrows or whatever. I want to clean this string so that it only contains letters, numbers and punctuation. Multiple spaces should be replaced by a single space too. </p>
  
  <p>Allowed punctuation: <code>, . : ; [ ] ( ) / \ ! @ # $ % ^ &amp; * + - _ { } &lt; &gt; = ? ~ | "</code></p>
  
  <p>Basically anything allowed in <a href="https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.3.0/com.ibm.zos.v2r3.ioaq100/ascii_table.gif" rel="nofollow noreferrer">this</a> ASCII table. </p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>let asciiOnly = y.replace(/[^a-zA-Z0-9\s]+/gm, '')
  let withoutSpacing = asciiOnly.replace(/\s{2,}/gm, ' ')
  </code></pre>
  
  <p>Regex101: <a href="https://regex101.com/r/0DC1tz/2" rel="nofollow noreferrer">https://regex101.com/r/0DC1tz/2</a></p>
  
  <p>I also tried the <code>[:punct:]</code> tag but apparently it's not supported by javascript. Is there a better way I can clean this string other than regex? A library or something maybe (I didn't find any). If not, how would I do this with regex? Would I have to edit the first regex to add every single character of punctuation? </p>
  
  <p>EDIT: I'm trying to paste an example string in the question but SO just removes characters it doesn't recognize so it looks like a normal string. <a href="https://pastebin.com/05zfKE4x" rel="nofollow noreferrer">Heres a paste</a>.</p>
  
  <p>EDIT2: I think this is what I needed:</p>
  
  <pre><code>let asciiOnly = x.replace(/[^\x20-\x7E]+/gm, '')
  let withoutSpacing = asciiOnly.replace(/\s{2,}/gm, ' ')
  </code></pre>
  
  <p>I'm testing it with different cases to make sure. </p>