title: In Ruby, how to UTF-8 encode this weird character?
body: <p>I'm importing content from an outside database that is infected with a variety of odd characters, e.g.</p>
  
  <pre><code>&gt; str
  =&gt; "Natureâ€™s Variety, Best Friends Animal Society team up"
  </code></pre>
  
  <p>From context it seems that <em>â€™</em> represents a right single-quote. In cp1252 encoding:</p>
  
  <pre><code>&gt; str.encode('cp1252')
  =&gt; "Nature\xE2\x80\x99s Variety, Best Friends Animal Society team up"
  </code></pre>
  
  <p>So how do I convert it to the correct UTF-8 character? Here's what I've tried:</p>
  
  <pre><code>&gt; str.encode('UTF-8')
  =&gt; "Natureâ€™s Variety, Best Friends Animal Society team up"
  
  &gt; str.encode('cp1252').encode('UTF-8')
  =&gt; "Natureâ€™s Variety, Best Friends Animal Society team up"
  
  &gt; str.encode('UTF-8', invalid: :replace, replace: '?', undef: :replace)
  =&gt; "Natureâ€™s Variety, Best Friends Animal Society team up"
  
  &gt; str.encode('cp1252').encode('UTF-8', invalid: :replace, replace: '?', undef: :replace)                                                                  
  =&gt; "Natureâ€™s Variety, Best Friends Animal Society team up"
  </code></pre>
  
  <p>I'd rather find a way to do a generic re-encoding so that it will handle all such miss-encoded characters. But if I have to I'll do individual search and replacing. But I'm not able to make that work either:</p>
  
  <pre><code>&gt; str.encode('cp1252').gsub('\xE2/x80/x99', "'")
  =&gt; "Nature\xE2\x80\x99s Variety, Best Friends Animal Society team up"
  
  &gt; str.encode('cp1252').gsub(%r{\xE2\x80\x99}, "'")
  SyntaxError: unexpected tIDENTIFIER, expecting $end
  
  &gt; str.encode('cp1252').gsub(Regexp.escape('\xE2\x80\x99'), "'")
  =&gt; "Nature\xE2\x80\x99s Variety, Best Friends Animal Society team up"
  </code></pre>
  
  <p>I'd like to do this, but I can't even paste these characters into my REPL:</p>
  
  <pre><code>&gt; str.gsub('â€™', "'")
  </code></pre>
  
  <p>When I try I get:</p>
  
  <pre><code>&gt; str.gsub('C"b,b,b
  * "', ",")
  =&gt; "Natureâ€™s Variety, Best Friends Animal Society team up"
  </code></pre>
  
  <p>Frustrating. Any suggestions on how to encode this properly into UTF-8?</p>
  
  <p>Edit: At the request for the actual bytes in the string:</p>
  
  <pre><code>&gt; str.bytes.to_a.join(' ')
  =&gt; "78 97 116 117 114 101 195 162 226 130 172 226 132 162 115 32 86 97 114 105 101 116 121 44 32 66 101 115 116 32 70 114 105 101 110 100 115 32 65 110 105 109 97 108 32 83 111 99 105 101 116 121 32 116 101 97 109 32 117 112"
  </code></pre>