Take the 2-minute tour ×

I have two strings:

"50's & 60's"


"50's &amp; 60's"

and they need to be a match.

Is there a way that I can do something to the string, maybe HTML decode before I compare?

share|improve this question

2 Answers 2

You can use CGI::unescapeHTML or its synonym CGI::unescape_html:

require 'cgi'
CGI::unescape_html "50's &amp; 60's" # => "50's & 60's"
share|improve this answer
any idea why this doesn't work with non-breaking spaces? --> >> CGI::unescapeHTML("sdf&nbsp;sdsdf") => "sdf&nbsp;sdsdf" –  Matthias Jul 4 '12 at 16:44
require 'rubygems'
require 'hpricot'

Hpricot("50's &amp; 60's", :xhtml_strict => true).to_plain_text # => "50's & 60's"
share|improve this answer
Using Hpricot is major overkill for this, and using a side-effect of the module's primary purpose, which is XML/HTML parsing. –  the Tin Man Feb 21 '12 at 18:55
they way you can do things in ruby are different, I don't know of the author already using that gems However this is just another possible solution rather than using cgi gem. No pressure, just alternative. And can't agree with you more. –  alexsuslin Feb 21 '12 at 19:33

Your Answer

