title: General method to trim non-printable characters in Clojure
body: <p>I encountered a bug where I couldn't match two seemingly 'identical' strings together. For example, the following two strings fail to match:
  &quot;sample&quot; and &quot;​sample&quot;.</p>
  <p>To replicate the issue, one can run the following in Clojure.</p>
  <pre><code>(= &quot;sample&quot; &quot;​sample&quot;) ; returns false
  </code></pre>
  <p>After an hour of frustrated debugging, I discovered that there was a <strong>zero-width space</strong> at the front of the second string! Removing it from this particular example via a backspace is trivial. However I have a database of strings that I'm matching, and it seems like there are multiple strings facing this issue. My question is: <strong>is there a general method to trim zero-width spaces in Clojure?</strong></p>
  <p>Some method's I've tried:</p>
  <pre><code>(count (clojure.string/trim &quot;​abc&quot;)) ; returns 4
  </code></pre>
  <pre><code>(count (clojure.string/replace &quot;​abc&quot; #&quot;\s&quot; &quot;&quot;)) ; returns 4
  </code></pre>
  <p>This thread <a href="https://stackoverflow.com/questions/11305797/remove-zero-width-space-characters-from-a-javascript-string">Remove zero-width space characters from a JavaScript string</a> does provide a solution with regular expressions that works in this example, i.e.</p>
  <pre><code>(count (clojure.string/replace &quot;​abc&quot; #&quot;[\u200B-\u200D\uFEFF]&quot; &quot;&quot;)) ; returns 3
  </code></pre>
  <p>However, as stated in the post itself, there are many other potential ascii characters that may be invisible. So I'm still interested if there's a more general method that doesn't rely on listing all possible invisible unicode symbols.</p>